Java - Spring framework - adding property file in application

less than 1 minute read

1. Add the following code in applicationContext-config.xml

1
2
3
4
5
6
7
8
<bean id="myProperties"
      class="org.springframework.beans.factory.config.PropertiesFactoryBean">
  <property name="locations">
    <list>
      <value>classpath*:my.properties</value>
    </list>
  </property>
</bean>

2. get an instance of myPropertes in code

1
java.util.Properties properties = (java.util.Properties)ApplicationContextProvider.getApplicationContext().getBean("myProperties")