项目开发过程中可能会需要区分不同开发环境的服务配置以及资源配置,例如测试环境、UAT环境、生产环境下不同的配置文件等。使用Maven的Profiles配置可以解决这一问题。
一、添加目录
dev、prod、uat三个环境,使用三个目录加以区分。
二、添加Profiles
<profiles>
<profile>
<!-- 本地开发环境 -->
<id>dev</id>
<activation>
<property>
<name>profiles.active</name>
<value>dev</value>
</property>
</activation>
</profile>
<profile>
<!-- UAT测试环境 -->
<id>uat</id>
<activation>
<property>
<name>profiles.active</name>
<value>uat</value>
</property>
</activation>
</profile>
<profile>
<!-- 生产环境 -->
<id>pro</id>
<activation>
<property>
<name>profiles.active</name>
<value>pro</value>
</property>
</activation>
</profile>
</profiles>
三、配置Resource
<build>
<resources>
<resource>
<directory>src/main/resources/config/${profiles.active}</directory>
</resource>
</resources>
</build>
四、指定Profile
<properties>
<profiles.active>uat</profiles.active>
</properties>
配置完成。仅通过修改profiles.active即可改变config文件的打包目录。
注意此profile和springboot的profile是有区别的。不可混淆。