Sunday, January 11, 2015

Reading properties file with Spring framework

Good day, I'd learned a new way of reading properties file with Spring. Usually when setting up a project with Spring framework, one common thing should have in Spring is following code:
   <bean id="applicationProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
        <property name="locations">

    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

        <property name="properties" ref="applicationProperties" />


I guess that was the classic design of a Spring project. Let's assume the file containing following content:


In order to read that properties, this is what I did in a my class:
public class MyClass
   protected Logger log = Logger.getLogger(this.getClass().getName());

   private String filePath;

No comments: