Spring Boot Profiles for the partition configuration
Benefits: You can switch through different environments spring.profiles.active
Configuration Location: Spring Boot project under application.properties
Configuration format: (application- {profile} .properties) will load the appropriate default profile according to the configuration
Configuration Example:
application-dev.properties
application-test.properties
application-prod.properties
spring.profiles.active=test 此时读取application-test-properties文件
spring.profiles.active: prod,proddb,prodmq 同时激活三个配置
Extended: spring.profiles.include for superimposing profile
Configuration loading
- In application.properties wrote in a fixed dead
- Call switching environment by invoking the command execution
Typically the second method is more suitable for formal research and development, as follows:
1, change the application.xml
changed by spring.profiles.active = dev is spring.profiles.active = @ profileActive @
2、更改pom.xml
<profile>
<id>dev</id>
<properties>
<profileActive>dev</profileActive>
<maven.test.skip>true</maven.test.skip>
<scope.jar>compile</scope.jar>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>test</id>
<properties>
<profileActive>test</profileActive>
<maven.test.skip>true</maven.test.skip>
<scope.jar>provided</scope.jar>
</properties>
</profile>
<profile>
<id>demo</id>
<properties>
<profileActive>demo</profileActive>
<maven.test.skip>true</maven.test.skip>
<scope.jar>provided</scope.jar>
</properties>
</profile>
<profile>
<id>pro</id>
<properties>
<profileActive>pro</profileActive>
<maven.test.skip>true</maven.test.skip>
<scope.jar>provided</scope.jar>
</properties>
</profile>
3、在maven打包的时候执行命令
mvn clean ×××tall -Dmaven.test.skip=true -Ptest
4. Run the file application
-Dspring.profiles.active dev =