SpringBoot-spring.profiles.active partition configuration
Profiles of Spring Boot is used for partition configuration
Benefit: you can switch between different environments through spring.profiles.active
Configuration location: application.properties under Spring Boot project
Configuration format: (application- {profile} .properties) loads the corresponding configuration file according to the configuration by default
Example configuration:
Application-dev.properties
Application-test.properties
Application-prod.properties
Spring.profiles.active=test now reads the application-test-properties file spring.profiles.active: prod,proddb,prodmq to activate three configurations at the same time
Extension: spring.profiles.include for overlaying profile
Configure loading mode
Switch environment invocation by calling execution command in application.properties
Usually, the second method is more suitable for formal research and development, and the code is as follows:
1. Change application.xml
Change from spring.profiles.active=dev to spring.profiles.active=@profileActive@
2. Change pom.xml
Dev
Dev
True
Compile
True
Test
Test
True
Provided
Demo
Demo
True
Provided
Pro
Pro
True
Provided
3. Execute commands when maven is packaged
Mvn clean × × tall-Dmaven.test.skip=true-Ptest
4. Execute commands in application
-Dspring.profiles.active=dev