springboot学习之maven多环境打包的几种方式

在应用部署的时候,往往遇到需要发布到不同环境的情况,而每个环境的数据库信息、密钥信息等可能会存在差异。

1.在默认的application.properties或者yaml中设置profile

spring.profiles.active=@spring.profiles@
#低版本的springboot中application.properties中的参数写法为 ${param}
#我目前测试过的在Spring Boot 1.3.0.RELEASE及以上版本中必须使用格式 @param@才能生效

打包命令:

mvn clean package -Pprod
#或者
clean package spring-boot:repackage -Dspring.profiles=test
clean package spring-boot:repackage -Dmaven.test.skip=true忽略Junit

命令解释:

-D,--define <arg>                      定义系统属性
-P,--activate-profiles <arg>           激活指定的profile文件列表(用逗号[,]隔开)

这样的话,多环境按需求选择环境打包就成功了。O(∩_∩)O

原文地址:https://www.cnblogs.com/zhaoyan001/p/8379494.html