一.多Resources实现方式
1.在src/main/resource创建一个env目录,再创建各个环境的子目录,再再各个环境子目录下创建名为config.properties的文件,每个键相同,值不同。
env/dev/config.properties
jdbc.username=dev
jdbc.password=123456
env/test/config.properties
jdbc.username=test
jdbc.password=888888
env/pro/config.properties
jdbc.username=root
jdbc.password=666666
2.配置profiles
<!-- Profiles -->
<profiles>
<profile>
<!-- 开发环境 -->
<id>dev</id>
<properties>
<env>dev</env>
</properties>
<activation>
<!-- 设置默认激活这个配置 -->
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<!-- 测试环境 -->
<id>test</id>
<properties>
<env>test</env>
</properties>
</profile>
<profile>
<!-- 发布环境 -->
<id>pro</id>
<properties>
<env>pro</env>
</properties>
</profile>
</profiles>
3.配置resource
<!-- Resources -->
<build>
<finalName>profile-app</finalName>
<!-- 定义了变量配置文件的地址 -->
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>env/dev/*</exclude>
<exclude>env/test/*</exclude>
<exclude>env/pro/*</exclude>
</excludes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources/env/${env}</directory>
<includes>
<include>*.*</include>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
网友评论