1、修改application.yml配置文件中的profiles.active为变量形式
spring:
profiles:
active: #spring.profiles.active#
2、在pom.xml中增加profiles配置
<profiles>
<profile>
<id>dev</id>
<properties>
<spring.profiles.active>dev</spring.profiles.active>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>le-pre</id>
<properties>
<spring.profiles.active>le-pre</spring.profiles.active>
</properties>
</profile>
<profile>
<id>le-pro</id>
<properties>
<spring.profiles.active>le-pro</spring.profiles.active>
</properties>
</profile>
<profile>
<id>me-pre</id>
<properties>
<spring.profiles.active>me-pre</spring.profiles.active>
</properties>
</profile>
<profile>
<id>me-pro</id>
<properties>
<spring.profiles.active>me-pro</spring.profiles.active>
</properties>
</profile>
<profile>
<id>xye-pre</id>
<properties>
<spring.profiles.active>xye-pre</spring.profiles.active>
</properties>
</profile>
<profile>
<id>xye-pro</id>
<properties>
<spring.profiles.active>xye-pro</spring.profiles.active>
</properties>
</profile>
</profiles>
3、在pom.xml中增加resources配置
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/xmldata/*.*</include>
<include>**/*.txt</include>
<include>**/*.yml</include>
<include>**/*.xml</include>
<include>**/log4j.properties</include>
<include>**/application-${spring.profiles.active}.properties</include>
</includes>
<filtering>true</filtering>
</resource>
<!--<resource>-->
<!--<directory>src/main/resources.${spring.profiles.active}</directory>-->
<!--<filtering>false</filtering>-->
<!--</resource>-->
</resources>
<finalName>test-${spring.profiles.active}</finalName>
</build>
4、在pom.xml中增加properties配置
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<skiptests>true</skiptests>
<resource.delimiter>#</resource.delimiter>
</properties>
5、将配置文件统一放到resources.config文件夹中
6、重启项目