To load multiple property files using Spring’s PropertyPlaceholderConfigurer, add <property name=”ignoreUnresolvablePlaceholders” value=”true” /> to the one that is loaded first like so:
<bean id=”propertyConfigurer”
class=”org.springframework.beans.factory.config.PropertyPlaceholderConfigurer”>
<property name=”location” value=”classpath:jdbc.properties” />
<property name=”ignoreUnresolvablePlaceholders” value=”true” />
</bean><bean id=”mailPropertyConfigurer”
class=”org.springframework.beans.factory.config.PropertyPlaceholderConfigurer”>
<property name=”location” value=”classpath:mail.properties” />
</bean>
This will make sure both files are loaded.
August 28, 2007 at 6:09 pm |
Just wanted to point out, it is also possible to use the ‘locations’ property of a single PropertyPlaceholderConfigurer:
sample1.properties
sample2.properties
August 28, 2007 at 6:12 pm |
with escaped xml this time…
<bean class=”org.springframework.beans.factory.config.PropertyPlaceholderConfigurer”>
<property name=”locations”>
<list>
<value>sample1.properties</value>
<value>sample2.properties</value>
</list>
</property>
</bean>
August 28, 2007 at 6:13 pm |
I guess that’s better.
Thanks!
November 28, 2007 at 12:21 am |
Thanks heaps, multiple files using locations is just what I wanted. btw, In case any punters need to know how to reference properties in spring:
Jol.
November 28, 2007 at 12:22 am |
that should have read:
.. < constructor-arg index=”3″ value=”${notifications.fromName.hoojano}” ..
November 28, 2007 at 12:23 am |
constructor-arg index=”3″ value=”${notifications.fromName.hoojano}”
December 16, 2007 at 12:38 am |
very interesting, but I don’t agree with you
Idetrorce
June 14, 2008 at 11:41 pm |
@Idetrorce: There were no opinions offered, how do you not agree with a usage example?
June 16, 2008 at 1:59 pm |
The ignoreUnresolvablePlaceholders is helpful when you have multiple Spring xml configurations file and each needs its own properties file. You can make it work with locations as well but the former is more cleaner IMO.
Thanks!
April 15, 2009 at 2:02 pm |
This is quite a up-to-date information. I’ll share it on Facebook.