Spring : Use PropertyOverrrideConfigurer to target different deployment environments

This page last changed on Oct 06, 2007 by Kees de Kooter

The challenge

Make spring applications easily adaptable for diffent target environments (like "test", "staging" and "live"), without having to change the applicationContext.xml file. Nice to have: enable system administrators to change the configuration without repackaging.

As always the spring framework offers a couple of excellent solutions for this.


The PropertyPlaceholderConfigurer provides runtime replacement of variables like ${dbname} in the application context xml. The downside of this solution is that you always have to provide all the values for all the variables, otherwise a BeanDefinitionStoreException will be thrown.

That is why I prefer


PropertyOverrideConfigurer enables you to override existing properties in the context file. The key is the reference to the property (<bean-id>.<property-name>) and the value is the value to set, eg.


The PropertyOverrideConfigurer needs to be defined as the first bean in the context.xml file.

    <property name="locations">
    <property name="ignoreResourceNotFound"    value="true"/>
    <property name="ignoreInvalidKeys" value="true"/>

Note the following details: