一、首先在项目中的配置
二、pom.xml配置
<profiles>
<profile>
<id>alpha</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<profiles.active>alpha</profiles.active>
</properties>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</profile>
<profile>
<id>rc</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<profiles.active>rc</profiles.active>
</properties>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</profile>
<profile>
<id>release</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<profiles.active>release</profiles.active>
</properties>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</profile>
</profiles>
三、application.properties中配置
spring.profiles.active = @profiles.active@
注意这里的值 @profiles.active@ ,该值为pom.xml中配置的值
环境的判断是根据<activeByDefault>true</activeByDefault> 标签获取,如果该标签为 true ,在表示为当前环境,并且在 idea 工具中能够显示当前环境
四、Jenkins 配置
只需在环境构建的时候指定当前环境
clean install -Dmaven.test.skip=true -Prc
五、测试
有关 Jenkins 的搭建可以参考
https://blog.csdn.net/weixin_45267345/article/details/116158220