dev、test、uat、sit、prod多环境,IDEA动态打包的几种方式
背景
实际软件开发工作中,软件会经历dev、test、uat、sit、prod多个环境的部署、测试运行,我们往往需要根据不同的环境配置设置打包属性。SpringBoot项目虽然可以通过spring.profile.active即可动态切换比较简单,但是对于pom.xml动态配置打jar/war包不好配置,本文将介绍几种方式供大家参考。同时由于网上只有在idea中如何进行配置使用,但是没有idea配置运行profile失效的问题解决的教程,于是我便根据我实际遇到的问题将解决方案分享给大家。
Spring Boot
项目结构如图:
配置属性
在application.properties
中配置要激活的具体环境配置文件
# 这里test对应application-test.properties文件,可以切换成自己想使用的配置文件
spring.profiles.active=test
运行应用
可以看到这里提示我们激活的是application-test.properties
Maven
通过这种方式可以动态配置SpringBoot项目在不同环境的配置,但是当我们想要在不同环境通过上面的方式动态选择打jar/war
包时就不太方便了,因此接下来介绍通过maven动态配置profile实现动态切换打包的配置信息
配置pom.xml
1、project>>build>>plugins下添加maven-resources-plugin
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
</plugin>
</plugins>
</build>
2、project>>build下添加resources
配置静态资源,这一步主要筛选需要进行属性渲染的配置文件
<build>
<resources>
<resource>
<directory>src/main/java</directory>