Load property file outside the war file using Spring 3


At times it is required to load properties not present in the war file. Typical usage can be have a war/jar file bundled and having property file for different environment such as dev, QA and PROD. It easy to put outside the war so that everytime build is not required. Fortunately is pretty simple in Spring 3.

Just mention this in spring config

<bean id="placeholderConfigConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName">
    <value>SYSTEM_PROPERTIES_MODE_OVERRIDE</value>
</property>
<property name="ignoreUnresolvablePlaceholders">
    <value>true</value>
</property>
<bean
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="file:${config}" />
</bean>

The value of config can be set a -Dconfig in runtime environment. Like it project is run using maven it can be set as MAVEN_OPTS parameter.

It you want smarter way then

 <context:property-placeholder location="file:${config}"/>

One thought on “Load property file outside the war file using Spring 3

Leave a Reply to burnpit.us Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s