Reputation: 4114
I have a project that i have divided into several subprojects, so this would be the hierarchy
parent
-project A
-project B
Now in project A I define my properties files like this:
<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>
Now my project B also needs a property file, and I feel like this properties file belongs in the B subproject. How can I do to "incorporate" this properties file into the propertyPlaceHolderConfigurer bean without replacing the previously loaded property files from project A?
Upvotes: 3
Views: 786
Reputation: 1936
Place your submodule's property files in src/main/resources/META-INF, so you can load them from the parent as follows:
<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>
From the Spring documentation:
The " classpath*:" prefix can also be combined with a PathMatcher pattern in the rest of the location path, for example " classpath*:META-INF/*-beans.xml". [...]
Please note that " classpath*:" when combined with Ant-style patterns will only work reliably with at least one root directory before the pattern starts, unless the actual target files reside in the file system. This means that a pattern like " classpath*:*.xml" will not retrieve files from the root of jar files but rather only from the root of expanded directories. [...]
Upvotes: 2