SpringBoot-- multi-environment deployment configuration file

Create application- {profile} .properties configuration file in the resources, which is an arbitrary profile name:
test: Test Environment
prod: online environment
pre-prod: pre-release environment
These profiles can be added or overwrite the file attribute application.properties
 
In the environment variables, spring.profiles.active specify the profile such as:
java -jar -Dspring.profiles.active=prod ....jar
 
Use war deploy, add the system attribute is a better way to tomcat, for example, edit catalina.sh
Add the following to the head sh file:
JAVA_OPTS="-Dspring.profiles.active=prod"
 
In the multi-environment deployment, normally resources may not target directory environment configuration file, mainly for security reasons, the configuration file can be placed in a specific directory and directory configuration file is specified with spring.config.loaction.
java -jar -Dspring.config.location=file:env/ -Dspring.profiles.active=test target/....jar
Configuration files in the current directory env directory,
 
springboot will automatically search classpath:, calsspath: / config, file:, file: / config configuration files in those directories priority from low to high.
 
@Profile comment
@Profile annotation can be combined @Configuration and @Component used in order to determine whether the class configuration take effect.
 
 

Guess you like

Origin www.cnblogs.com/jsersudo/p/11652092.html