【发布时间】:2016-05-11 18:55:59
【问题描述】:
我有一个包含多个模块的Maven 项目。 Module ModuleB 使用 ModuleA 作为内部 Maven 依赖项。在 moduleA 中,我有一个 Spring xml 配置 module.a.xml,它加载了一个 module.a.properties 文件。在 moduleB 的 Spring xml 配置中,我将 module.b.properties 文件与 module.a.xml 配置一起导入。
最后我得到了一个带有两个属性文件导入的Spring xml 配置。根据导入的顺序,我只能访问一个文件的属性:module.a.properties 或 module.b.properties。如何同时使用这两个属性?
使用PropertyPlaceholderConfigurer 的解决方案的问题是属性文件位于不同的模块中,模块B 不应该担心模块A 的属性文件。
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" id="corePlaceHolder">
<property name="locations">
<list>
<value>classpath:modula.a.properties</value>
<value>classpath:modula.b.properties</value>
</list>
</property>
</bean>
使用ignore-unresolvable="true" 的问题是很容易遗漏一个被遗忘的属性,而将ignore-unresolvable="true" 放在property-placeholder 上很容易遗漏。
<context:property-placeholder location="module.a.properties" order="0" ignore-unresolvable="true"/>
<context:property-placeholder location="module.b.properties" order="1" ignore-unresolvable="true"/>
【问题讨论】:
标签: java xml spring maven properties