当maveny与springboot同时对多环境进行控制时以maven为主
这时在maven中添加如下配置:
<profiles>
<profile>
<id>evn_dev</id>
<properties>
<profile.active>dev</profile.active>
</properties>
</profile>
<profile>
<id>env_prod</id>
<properties>
<profile.active>prod</profile.active>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>evn_dev</id>
<properties>
<profile.active>test</profile.active>
</properties>
</profile>
</profiles>
而在springboot配置文件中这样写
spring:
profiles:
active: @profile.active@
# include 先加载devMVC和devDB 最后加载dev
# include: devMVC,devDB
# group 先加载dev 再加载devMVC和devDB
group:
"dev": devMVC,devDB
"prod": prodMVC,prodDB
注: 1、<profile.active>test</profile.active>为设置环境名称
2、true设置默认使用该环境
3、@profile.active@ 为springboot读取maven中的配置
4、在idea中使用@profile.active@获取maven中配置时,可能产生切换maven中开启的环境配置后,启动项目,结果任然加载的是之前的环境配置,这时需要手动编译方可成功切换