Spring files can be used to restrict creation of beans to specific environments. In this example a ConcurrentMapCacheManager is used for the development environment, whereas EhCacheCacheManage is used for the production environment.
The active profile can be set by passing the spring.profiles.active
value as a JVM system property when starting the application:
-Dspring.profiles.active=dev
Alternatively, the profile can be set in application.properties
:
spring.profiles.active=prod
To make a profile the default profile, we add "default" to the profile:
@Profile("prod", "default")
The default profile is used if no spring.profiles.active
is set.
The example code is a Kotlin port of the code from Spring Profiles example