Loading multiple property files

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. ๐Ÿ™‚

Advertisements

11 thoughts on “Loading multiple property files

  1. Just wanted to point out, it is also possible to use the ‘locations’ property of a single PropertyPlaceholderConfigurer:

    sample1.properties
    sample2.properties

  2. 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>

  3. 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.

  4. 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!

  5. Use different properties per environment and use your build script to create the build with the appropriate properties file. Good luck!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s