Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Spring Profiles provide a way to segregate parts of your application configuration and make it only available in certain environments. Any @Component or @Configuration can be marked with @Profile to limit when it is loaded:

...


In addition to

Include Page
_PropertiesFileJavaR10PropertiesFileJava
_PropertiesFileJavaR10PropertiesFileJava
 files, profile-specific properties can also be defined using the naming convention application-{profile}.properties. You are advised to only use lower case filenames and lower case profile names because Spring profile names are case sensitive. The Environment has a set of default profiles (by default [default]) which are used if no active profiles are set (i.e. if no profiles are explicitly activated then properties from application-default.properties are loaded).

Profile-specific properties are loaded from the same locations as standard

Include Page
_PropertiesFileJavaR10PropertiesFileJava
_PropertiesFileJavaR10PropertiesFileJava
, with profile-specific files always overriding the non-specific ones irrespective of whether the profile-specific files are inside or outside your packaged jar.

...

Spring profiles can be activated via JVM argument spring.profiles.active. When a

Include Page
_ConfigLocation
_ConfigLocation
 is set the active profiles can also be set by placing a 'bootstrap.properties' in
Include Page
_PropertiesBootstrap
_PropertiesBootstrap
 in the config location directory. The 'bootstrap.properties' should
Include Page
_PropertiesBootstrap
_PropertiesBootstrap
 should then contain the spring.profiles.active property, do not use the two mechanisms (JVM argument and 'bootstrap.properties'
Include Page
_PropertiesBootstrap
_PropertiesBootstrap
) at the same time. The application server must be restarted after changing the active Spring profiles.

An example bootstrap.properties file

Include Page
_PropertiesBootstrap
_PropertiesBootstrap
 file:

Code Block
titlebootstrap.properties
spring.profiles.active=native, development-tools
spring.cloud.config.server.bootstrap=true
spring.cloud.config.server.native.searchLocations=file:${spring.config.location:.}

...

When it runs it will pick up the external configuration from the default local config server on port 8888 if it is running. To modify the startup behavior you can change the location of the config server using bootstrap.properties

Include Page
_PropertiesBootstrap
_PropertiesBootstrap
 (such as
Include Page
_PropertiesFileJavaR10PropertiesFileJava
_PropertiesFileJavaR10PropertiesFileJava
 but for the bootstrap phase of an application context).

...