Idea: Maven supports the profile feature, when packaged with Maven profile, you can package the specified directory and specify the file, and you can modify the variables in the file. Spring boot also supports the profile feature, as long as you specify SPRING.PROFILES.ACTIVE=XXX in the application.properties file, where xxx is a variable and when MAVEN is packaged, You can modify this variable.
1. Configuring the profile for Maven
< find different profiles!--different environments--<profiles> <profile> <id>dev</id> < Properties> <profiles.active>dev</profiles.active> <maven.test.skip>true</maven.test.skip> </properties> <activation> <ACTIVEBYDEFAULT&G Ttrue</activeByDefault> </activation> </profile> <profile> <ID&G T;sit</id> <properties> <profiles.active>sit</profiles.active> <maven.test.skip>true</maven.test.skip> </properties> </profile> <profile> <ID&G T;prd1</id> <properties> <profiles.active>prd1</profiles.active> <maven.test.skip>true</maven.test.skip> <scope.jar>provided</scope.jar> </properties> </profile> <profile> <id>prd2</id> <properties> <profiles.active>prd2</profiles.active> <maven.test.skip>true</maven.test.skip> <scope.jar>provided</scope.jar> </properties> </profile> </profiles>
Where profiles.active is a variable that we define, can be specified by the MVN command, and can be accessed by others
To configure a modifiable accessible resource file in build
<resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> <excludes> <exclude>application-dev.properties</exclud E> <exclude>application-sit.properties</exclude> <exclude>appli Cation-prd1.properties</exclude> <exclude>application-prd2.properties</exclude> </excludes> </resource> <resource> <directory>src/m Ain/resources</directory> <filtering>true</filtering> <includes> <include>application-${profiles.active}.proper Ties</include> <include>application.properties</include> </includes > </resource> </resources>
Where ${profiles.active} is the variable specified in the above profile
2. Configuring the profile of the Springboot
This is specified by spring.profiles.active
Specify [email protected]@] in application.properties to combine maven with Springboot profile
3. Packaging command: mvn clean package-dmaven.test.skip=true-p prod-e
Integrated maven and Spring boot profile features