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 |
---|
title | bootstrap.properties |
---|
|
spring.profiles.active=native, development-tools,dashboard,customerdata-client,trace-sql-store,process-sql-store,reporting-sql-store,comments-sql-store,scheduler-quartz
spring.cloud.config.location=classpath:/
spring.config.server.bootstrap=trueadditional-location=
spring.cloud.config.server.native.searchLocations=file:${spring.config.location:.}},${spring.config.additional-location}
spring.cloud.config.server.bootstrap=true |
Code Block |
---|
language | text |
---|
title | Configuration of Spring Profiles |
---|
collapse | true |
---|
|
java -Dspring.profiles.active="native,cmis-client,comments-sql-store,customerdata-sql-store,dashboard,development-tools,managementservice-client,process-sql-store,publisher-client,reporting-sql-store,trace-sql-store" -Dspring.config.location="%~dp0/Runtime/Java/conf/" -jar Runtime/Java/bin/blueriq-runtime-standalone.jar
|
...
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).
Further reading
...