You can use PropertyPlaceholderConfigurer to read your properties file from either classpath or WEB-INF or from file system adding below configuration to your applicationContext.xml file:
A. File in Classpath:
<bean id="dbProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:db.properties" />
</bean>
The keys defined in the db.properties
file can be read using ${key name}
.
Example: Consider, your properties file contain
jdbc.url=jdbc:mysql://localhost:3306/dbName
then you can read this property using below command
<property name="url" value="${jdbc.url}" />
B. File in WEB-INF:
When your properties file in under WEB-INF directory, then you just add below code snippet under dbProperties
bean & it'll starts looking your properties file in the WEB-INF directory of the application.
<property name="location" value="WEB-INF/db.properties" />
C. File on File System:
When you want to read file from file system then just add below code in dbProperties
bean.
<property name="location" value="file:///D:/database/db.properties" />
NOTE: You can either use file:///
or file:
in case C
.
Hope this solves your problem.