Using Properties file for Strings externalizing: PropertyPlaceHolderConfigurer
- This is used to access string values from a properties file into the spring.xml file
We can externalize values for <property> variables in the spring,xml file, to a .properties file as below:
1)replace the value strings in the spring.xml with a $variableName instead; as below:
2)Now create and include this string along with the desired value within the .properties files and place it in the same location as is the spring.xml
3) finally, configure the PropertiesPlaceHolderConfigurer class within the sping.xml file as another bean, as below:
<beans>
<bean id=".." class="...">
<property name="x" value="${valueNameAsInPropFile}" />
<bean>
<bean class="org.springframework.beans.factory.config.PropertyPlaceHolderConfigurer">
<property name="locations" value="<<filename>>.properties"/>
</bean>
</beans>
_______________________________________________________________________________
No comments:
Post a Comment