This is an ‘oldie’, but I just needed it again, so I thought it worth describing.

The Spring framework has an easy way to externalize some of the properties of your bean definition files into a Java properties file, using a PropertyPlaceholderConfigurer bean.

As I was looking to write this, I found a couple other articles with a lot of additional, useful information on the subject:

However, my immediate case is a simple one of using a “hardcoded” default property value with a System Property override. For that case, the Spring config looks something like this:

    <!-- Property placeholders, overridable by -->  
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
        <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>  
        <property name='properties'>  
                <!-- Default values if not set in -->  
                <prop key="environment">test</prop>  

(I gather that as of Spring 3.1, PropertySourcesPlaceholderConfigurer is preferred to PropertyPlaceholderConfigurer, but my current customer is on older Spring for the moment.)