Springboot自带有环境隔离,为什么还需要maven的环境隔离呢?个人认为是有以下几个原因:
- springboot的环境隔离是通过名字进行隔离的,而使用maven的话,可以通过目录进行隔离,方便管理
- 对于其他的一下第三方工具管理的时候,方便统一名字管理,比如说:Jenkins,docket...
- 防止在配置生产环境的时候忘记修改spring.profiles.active导致故障,或者一不小心打错了导致现场故障
准备工作:
添加三个环境:
配置方式,在pom文件上,添加sources节点,将所有的环境添加上去
<build>
<resources>
<resource>
<directory>src/main/resources/</directory>
<excludes>
<exclude>conf/dev/*</exclude>
<exclude>conf/local/*</exclude>
<exclude>conf/prod/*</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources/conf/${profiles.active}</directory>
</resource>
</resources>
</build>
再配置激活的环境
<profiles>
<profile>
<id>dev</id>
<properties>
<profiles.active>dev</profiles.active>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
</profiles>