Maven profile的properties在yaml配置文件替换失效问题
Maven profile的properties在yaml配置文件替换失效问题
原因:spring-boot项目需要使用@进行分割,如yaml配置文件中的填充符${port.gateway}替换为@port.gateway@
原来错误的配置
pom文件:
<profiles>
<!-- 生产 -->
<profile>
<id>prod</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<profile.name>prod</profile.name>
<!-- 省略其它... -->
</properties>
</profile>
<!-- 开发环境 -->
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<profile.name>prod</profile.name>
<!-- 省略其它... -->
</properties>
</profile>
<!-- 本地测试 -->
<profile>
<id>local</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<profile.name>dev</profile.name>
<!-- 省略其它... -->
</properties>
</profile>
</profiles>
<build>
<resources>
<!-- 先指定 src/main/resources下所有文件及文件夹为资源文件 -->
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>**/*.xlsx</exclude>
</excludes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.xlsx</include>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
yaml配置:
spring:
profiles:
active: ${profile.name}
修改后的配置
pom文件:保持不变
yaml配置:
spring:
profiles:
active: @profile.name@