tags:

views:

1710

answers:

2

I need to load a specific applicationContext.xml file according to a given system property. This itself loads a file with the actual configuration. Therefore I need 2 PropertyPlaceHolderConfigurer, one which resolves the system param, and the other one within the actual configuration.

Any ideas how to do this?

+5  A: 

Yes you can do more than one. Be sure to set ignoreUnresolvablePlaceholders so that the first will ignore any placeholders that it can't resolve.

<bean id="ppConfig1" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
   <property name="ignoreUnresolvablePlaceholders" value="true"/>
   <property name="locations">
    <list>
             <value>classpath*:/my.properties</value>
    </list>
  </property>
</bean>

<bean id="ppConfig2" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
   <property name="ignoreUnresolvablePlaceholders" value="false"/>
   <property name="locations">
    <list>
             <value>classpath*:/myOther.properties</value>
    </list>
  </property>
</bean>

Depending on your application, you should investigate systemPropertiesMode, it allows you to load properties from a file, but allow the system properties to override values in the property file if set.

flicken
+1  A: 

Beware -- there might be a bug related to multiple configurers. See http://jira.springframework.org/browse/SPR-5719 for more details.

I'm unable to get multiple to work locally... but I'm not yet blaming anyone but myself.

trenton