遇到的问题:
1、单个配置文件过大、多人协同困难
2、每一个环境又要部署给不同的租户
解决方案:
1、所有环境都一致且不会修改的配置放在application.yml里
2、每个环境创建该环境的配置文件夹,该环境下用到的配置都放在该文件夹下
3、对应环境文件夹下的配置文件拆分为多个
直接上配置
1、profiles的配置
<profiles>
<profile>
<id>local</id>
<properties>
<env>local,part</env>
<profiles.active>local</profiles.active>
</properties>
<activation>
<!-- 默认环境 -->
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>test</id>
<properties>
<env>test,part</env>
<profiles.active>test</profiles.active>
</properties>
</profile>
<profile>
<id>pre</id>
<properties>
<env>pre,part</env>
<profiles.active>pre</profiles.active>
</properties>
</profile>
<profile>
<id>staging</id>
<properties>
<env>staging,part</env>
<profiles.active>staging</profiles.active>
</properties>
</profile>
<profile>
<id>product</id>
<properties>
<env>product,part</env>
<profiles.active>product</profiles.active>
</properties>
</profile>
</profiles>
2、配置文件结构
image.png
3、打包配置
<build>
<resources>
<resource>
<directory>src/main/resources/profiles/${profiles.active}</directory>
<includes>
<include>*.*</include>
</includes>
<filtering>true</filtering>
<targetPath>./</targetPath>
</resource>
<resource>
<directory>src/main/resources</directory>
<targetPath>./</targetPath>
<filtering>true</filtering>
<excludes>
<exclude>profiles/**</exclude>
</excludes>
</resource>
</resources>
</build>
网友评论