Reading properties file in Spring
There are multiple ways to read properties file in Spring
Let us say you have database user name , password etc configured in jdbc.properties and would like to inject the values at run time.
Here is what will go in applicationContext.xml
<bean id=”propertyConfigurer”>
<property name=”locations”>
<list>
<value>classpath:environment.properties.properties</value>
</list>
</property>
</bean>
<bean id=”dataSource” destroy-method=”close”>
<property name=”driverClass” value=”${jdbc.driverClass}”/>
<property name=”jdbcUrl” value=”${jdbc.url}”/>
<property name=”user” value=”${jdbc.user}”/>
<property name=”password” value=”${jdbc.password}”/>
<property name=”minPoolSize” value=”${jdbc.minPoolSize}”/>
<property name=”maxPoolSize” value=”${jdbc.maxPoolSize}”/>
</bean>
and this will be your properties file
jdbc.driverClass=oracle.jdbc.driver.OracleDriver
jdbc.url=jdbc:oracle:thin:@abc.com:1521:ORAC
jdbc.user=hello
jdbc.password=hello
jdbc.minPoolSize=1
jdbc.maxPoolSize=10
At run time, the properties file value will be injected into the applicationContext.xml



Thanks John.
The solutions is incomplete…
You can user PropertyPlaceHolderConfigurer
classpath:application.properties
<!–
file:/usr/config/web/application.properties
file:C:/dev/config/web/application.properties
–>