由于某种需求,我们需要依赖另一个应用的jar包以及其中某几个xml的配置文件,恰好引用的这几个xml文件中,用到的占位符。在aone以及本工程里面的antx.properties文件中已经完成了配置,但是在正式maven打包的时候,还是无法替换这些占位符。
怎样才能让这个占位符被成功替换呢?
maven打包原理
后续补充
解决方案
- ofc.kvstore.server=${ofc.kvstore.server}
- ofc.kvstore.port=${ofc.kvstore.port}
- 在引用jar包xml文件的本工程的xml配置文件的前面加上一段配置,强制使用我们新建的XX.properties文件中的占位符替换本文件加载的所有xml(1.xml,2.xml,3.xml)里面的占位符,例如:
- <bean @H_403_41@class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
- <property @H_403_41@name="locations">
- <list>
- <value>classpath:bean/XXX.properties</value>
- </list>
- </property>
- </bean>
- <import @H_403_41@resource="classpath:bean/1.xml"/>
- <import @H_403_41@resource="classpath:bean/2.xml"/>
- <import @H_403_41@resource="classpath:bean/3.xml"/>
- 配置主pom的resource,形如:
- <resources>
- <resource>
- <directory>src/main/java</directory>
- <filtering>true</filtering>
- <includes>
- <include>**/*.xml</include>
- <include>**/*.properties</include>
- </includes>
- </resource>
- <resource>
- <directory>src/main/resources</directory>
- <filtering>true</filtering>
- <includes>
- <include>**/*.*</include>
- <include>*.*</include>
- </includes>
- </resource>
- </resources>