問(wèn)題:之前的mvn多模塊項(xiàng)目因篇,我會(huì)在parent模塊下,創(chuàng)建幾個(gè)filter配置文件笔横,以實(shí)現(xiàn)不同環(huán)境不同配置竞滓。但是在搭建springboot的mvn多模塊框架時(shí),配置文件始終替換不了吹缔。
原因:仔細(xì)看springboot的官方文檔
https://docs.spring.io/spring-boot/docs/2.0.4.RELEASE/reference/htmlsingle/#using-boot-maven-plugin
Note that, since the application.properties and application.yml files accept Spring style placeholders ({…?}), the Maven filtering is changed to use @..@ placeholders. (You can override that by setting a Maven property called resource.delimiter.) 是說(shuō)springboot自己使用了{…?}占位符商佑,所以mvn打包的占位符使用@@
順手上一下示例代碼:
parent的pom中增加:
<profiles>
<profile>
<id>production</id>
<properties>
<env>prod</env>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<env>test</env>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
</profiles>
增加build配置:
<build>
<filters>
<filter>../parent/src/main/filters/${env}.properties</filter>
</filters>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>/.ftl</exclude>
<exclude>/-dynamic.xml</exclude>
<exclude>/mybatis//.xml</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>/.ftl</include>
<include>/-dynamic.xml</include>
<include>/mybatis//.xml</include>
</includes>
</resource>
</resources>
使用:
其他子模塊的yml中
url: @config.datasource.url@
解決:占位符改為使用@@ 問(wèn)題解決。
官方文檔沒事還是要仔細(xì)看看厢塘,尤其是note不能省茶没。