美文网首页程序员
Spring boot实现多环境配置

Spring boot实现多环境配置

作者: 龙行天下简书 | 来源:发表于2017-12-25 11:51 被阅读0次

在实际项目中,我们一般会放置一些配置文件,这些配置文件是区分环境的,一般环境有dev,test,prep,prod,分别对应开发,测试,预发布,生产。那么在spring boot项目中如何实现不同环境,使用不同的配置文件呢。

第一步:定义好不同环境的application.properties

image.png

application.properties 存放公用的一些配置。
以及最重要的配置 spring.profiles.active=@profiles.active@
application-dev.properties 对应开发环境
application-test.properties 对应测试环境
application-prep.properties 对应预生产环境
application-prod.properties 对应生产环境

第二步:pom中定义profile


image.png

第三步:maven命令打包
package -Dmaven.test.skip=true -Pdev

那么此时就会将application-dev.properties 和application.properties 的配置都打入包中了。

具体代码可以参考github
https://github.com/BruceZhangXL/wolf

相关文章

网友评论

    本文标题:Spring boot实现多环境配置

    本文链接:https://www.haomeiwen.com/subject/iuclgxtx.html