Welcome to my website. I am always posting links to photo albums, art, technology and other creations. Everything that you will see on my numerous personal sites is powered by the formVistaTM Website Management Engine.

icon.linkedin.jpgicon.twitter.jpg

  • Excellent Example and Explanation on How to Inject Properties from an External Properties File from Outside of a WAR in a Spring Application
    01/29/2014 8:39PM

    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"  
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
      <property name="locations"> 
        <list> 
          <value>classpath:database.properties</value> 
        </list> 
      </property> 
    </bean> 

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

Advanced Search

Categories

Archives