Loading multiple property files

By Ana

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. :)

10 Responses to “Loading multiple property files”

  1. Mark Fisher Says:

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

    sample1.properties
    sample2.properties

  2. Mark Fisher Says:

    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. Ana Says:

    I guess that’s better. :) Thanks!

  4. Jol Says:

    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.

  5. Jol Says:

    that should have read:
    .. < constructor-arg index=”3″ value=”${notifications.fromName.hoojano}” ..

  6. Jol Says:

    constructor-arg index=”3″ value=”${notifications.fromName.hoojano}”

  7. Idetrorce Says:

    very interesting, but I don’t agree with you
    Idetrorce

  8. Mike Says:

    @Idetrorce: There were no opinions offered, how do you not agree with a usage example?

  9. Santosh Says:

    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!

  10. How to Get Six Pack Fast Says:

    This is quite a up-to-date information. I’ll share it on Facebook.

Leave a Reply