blog.onlysimpler.com

A blog... only simpler.

By using an external properties file, the Spring configuration file can remain the same across all environments. Only the environment specific properties file needs to change.

In practise, each developer would have their own properties file, and each environment (development, test, production etc) would have properties specific to that environment.

The Spring configuration file:

<!-- Load an environment specific properties file -->
<bean id="propertyConfigurer" 
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="locations">
    <list>
      <value>environment.properties</value>
    </list>
  </property>
</bean>
    
<!-- Insert a property from 'environment.properties' into the configuration for a bean -->
<bean id="simpleBean" class="com.onlysimpler.spring.beans.SimpleBean">
  <property name="name" value="${property.name}"/>
</bean>

The environment.properties file:

property.name=This is a test property