2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

How to configure spring configuration file to take value from properties file present in classpath

Requirement is to get values from properties file, which is present in classpath and set the value in configuration xml file of spring.

How to do that?

userimage

To get value dynamically in spring configuration file we can use 'PropertyPlaceholderConfigurer' :

Add below bean configuration in configuration xml file

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations" value="classpath:/file.properties"/>
</bean>


Now we can pass values dynamically to property:

<property name="url" value="${jdbc.url}" />


Here
jdbc.url is is a key present in file.properties


Answer is