Application ScenariosWhen we develop, we will encounter the need to distinguish between formal environment, test environment, development environment using different parameters, such as database username and password. You can then use spring's propertyplaceholderconfigurer to configure variables that are affected by the environment, the way you use multiple profiles, but I don't think it's flexible enough, so I use Maven's profiles to do this, When packaged, Maven writes the file according to the specified configuration parameters. Configuration is divided into two types, one is the global configuration that is, in the. M2/conf/setting.xml configuration to achieve global, one is in the project Pom.xml configuration, here I do not use the global approach, not detailed, we mainly introduce the project configuration.
Implement
1.pom.xml Configuration
<build> <!--Configure the configuration file using variables--> <filters> <filter>src/main/resources/a
Pplication.properties</filter> </filters> <resources> <!--configuration file path--> <resource> <directory>src/main/resources</directory> <filte ring>true</filtering> </resource> </resources> </build> <profile s> <profile> <id>local</id> <properties> <po
M.env>dev</pom.env> <pom.ver>1.2.4</pom.ver> </properties> <activation> <!----> <activebydefault>true</activebydefau for the default-effective configuration group lt> </activation> </profile> <profile> <ID>DEV</ID&G
T <propeRties> <pom.env>dev</pom.env> <pom.ver>1.3.3</pom.ver>
</properties> </profile> <profile> <id>pro</id>
<properties> <pom.env>pro</pom.env> <pom.ver>1.3.5</pom.ver>
</properties> </profile> </profiles>
2.application.properties Configuration
ENV=${POM.ENV}
Ver=${pom.ver}
3. Implementation
When executed, add-P ${profile.id}, use the default can not add, I use the IDE with the tool to select the effective parameter group, in the profiles select the parameter group
MVN Clean Install-p Local
4. Summary
The steps are as follows: Pom.xml Add, Parameter el Expression in configuration file call variable execution is-p development parameter