springboot多环境配置两种方式

2019-07-25  本文已影响0人  只想做个俗人_贪财_好色

第一种就是springboot中默认的application.yml中添加
spring:
profiles:
active: 环境名
在application.yml同级目录中创建 application-环境名.yml 即可。
另外一种是通过maven
同样在application.yml 添加
spring:
profiles:
active: @env@
注意@@
另外在pom中添加

<profiles>
<profile>
<id>local</id>
<properties>
<env>local</env>
</properties>
<activation>

<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>dev</id>
<properties>
<env>dev</env>
</properties>
</profile>
</profiles>
我这里是添加了两个环境 local 、dev
注意要添加

<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
可能会有找不到 yml 情况

上一篇下一篇

猜你喜欢

热点阅读