Excellent Example and Explanation on How to Inject Properties from an External Properties File from Outside of a WAR in a Spring Application

I am doing some refactoring on a Spring MVC application, pulling out configuration data and login crentials from the spring.xml file.

What I want to do is to consolodate sensitive data into external .properties files that can be read, at runtime by the app and not require recompiling the war to make changes.

Thanks to Ben Northrop and Summa Technologies for such a clear, concise and well written article.

The long and the short of it (copied from the aforementioned article) is to add the following to your spring.xml

<bean id=”propertyPlaceholderConfigurer”  
  <property name=”locations”> 

<bean id=”dataSource” class=”com.mchange.v2.c3p0.ComboPooledDataSource”> 
  <property name=”user” value=”${db.user}”/> 
  <property name=”password” value=”${db.password}”/> 

Leave a Reply