springboot|解决:mvn多模块下filter配置替换

问题:之前的mvn多模块项目,我会在parent模块下,创建几个filter配置文件,以实现不同环境不同配置。但是在搭建springboot的mvn多模块框架时,配置文件始终替换不了。


springboot|解决:mvn多模块下filter配置替换_第1张图片
1.png

原因:仔细看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.) 是说springboot自己使用了{…​}占位符,所以mvn打包的占位符使用@@

顺手上一下示例代码:
parent的pom中增加:




production

prod




test

test


true


增加build配置:


../parent/src/main/filters/${env}.properties



src/main/resources
true

/.ftl
/-dynamic.xml
/mybatis//.xml



src/main/resources
false

/.ftl
/-dynamic.xml
/mybatis//.xml


使用:
其他子模块的yml中
url: @config.datasource.url@

解决:占位符改为使用@@ 问题解决。

官方文档没事还是要仔细看看,尤其是note不能省。

你可能感兴趣的:(springboot|解决:mvn多模块下filter配置替换)