[英]Add a properties file to the pre-existing PropertyPlaceholderConfigurer
我有一个项目,我已经分成几个子项目,所以这将是层次结构
parent
-project A
-project B
现在在项目AI中定义我的属性文件,如下所示:
<bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="properties" ref="myProperties" />
<property name="systemPropertiesModeName">
<value>SYSTEM_PROPERTIES_MODE_OVERRIDE</value>
</property>
</bean>
<bean id="myProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath:file1.properties</value>
<value>classpath:file2.properties</value>
<value>classpath:file3.properties</value>
</list>
</property>
</bean>
现在我的项目B也需要一个属性文件,我觉得这个属性文件属于B子项目。 如何将此属性文件“合并”到propertyPlaceHolderConfigurer bean中,而不从项目A替换以前加载的属性文件?
将子模块的属性文件放在src / main / resources / META-INF中,以便您可以从父项加载它们,如下所示:
<bean id="propertyPlaceholderConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreResourceNotFound" value="true" />
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="locations">
<list>
<value>classpath*:parent1.properties</
<value>classpath*:parent2.properties</value>
<!-- loads all submodules property-files --!>
<value>classpath*:/META-INF/*.properties</value>
</list>
</property>
</bean>
从Spring 文档 :
“classpath *:”前缀也可以与位置路径的其余部分中的PathMatcher模式组合,例如“classpath *:META-INF / * - beans.xml”。 [...]
请注意,“类路径*:”与Ant样式模式结合使用时,只能在模式启动前与至少一个根目录可靠地工作,除非实际目标文件驻留在文件系统中。 这意味着像“classpath *:*。xml”这样的模式不会从jar文件的根目录中检索文件,而只能从扩展目录的根目录中检索文件。 [...]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.