pom.xml文件设置
<!--MAVEN打包选择运行环境-->
<!-- 1:local(默认) 本地 2:dev 开发环境 3:test 测试环境 4:uat 用户验收测试 5.pro:生产环境-->
<profiles>
<profile>
<id>local</id>
<properties>
<profileActive>local</profileActive>
</properties>
<activation>
<!-- 配置为默认值 -->
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>test</id>
<properties>
<profileActive>test</profileActive>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<profileActive>prod</profileActive>
</properties>
</profile>
</profiles>
每一个<profile>
标签对应一个配置文件,id对应的就是application-**.yaml
在application.yaml中配置@profiles.active@
,代表加载哪个配置文件
spring:
profiles:
active: @profiles.active@
通过maven窗口选择配置文件
问题
可能会遇到一个问题Do not use @ for indentation
解决
pom中加入plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<!-- 指定过滤的表达式
<delimit>@</delimit> : 表示 过滤开头为 @ 结束为 @ 的内容,例如 @project.version@
<delimit>${*}</delimit> 表示 过滤${}包裹的内容,例如 ${project.vserion}
-->
<delimiters>@</delimiters>
<useDefaultDelimiters>false</useDefaultDelimiters>
</configuration>
</plugin>
然后重新载入