Newsletter |
Resource Bundle In Spring: Dynamically Loading The Values For Property Placeholders In XML
Spring » on Feb 11, 2012 { 5 Comments } By Sivateja
Let us see how to load the values into spring configuration file dynamically using ResourceBundle concept
- Instead of directly placing the values into xml we can load the values at run time for the dataSource properties using ResourceBundle
- If we want to get the dataSource properties at runtime from ResourceBundle, while configuring the bean into xml we should put bundle keys with expression language into the xml file like…
<bean id="id1" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName"> <value>${jdbc.driver}</value> </property> </bean>
In ResourceBundle
jdbc.driver = sun.jdbc.odbc.JdbcOdbcDriver
- In spring we have pre-defined class given, called PropertyPlaceholderConfigure and this class will read the data from the bundle and it will write the values into the configuration file
- PropertyPlaceholderConfigure given in
org.springframework.beans.factory.config.* package
ClientLogic
Resource res = new ClassPathResource("spconfig.xml"); XmlBeanFactory factory = new XmlBeanFactory(res); PropertyPlaceholderConfigur ppc = new PropertyPlaceholderConfigurer(); ppc.setLocation(new ClassPathResource(MyPropertiesFile.properties)); ppc.postProcessBeanFactory(factory);
Notes:
At line number 5, there spring container will read the properties file from bundle.
At line number 6, spring container will write the properties into XML file
Now will see one example..
You Might Also Like
::. About the Author .:: | ||
Comments
5 Responses to “Resource Bundle In Spring: Dynamically Loading The Values For Property Placeholders In XML”
hi,
ur site excellent
pls provide spring with hibernate
@Suresh
We are working on spring remaining modules…!
Will get back to you ASAP.
Thank you.
Your Explanation on Spring JDBC,as well as explanation on IOC superb,,,,any one can learn spring easily with java4s…
Thanks Java4s
hi , I want dynamically reload the property file without restarting the server. how to implement this in spring.. need this urgent.. can you please me.
Hi Team,
There is some typo mistake as "PropertyPlaceholderConfigur ppc = new PropertyPlaceholderConfigurer();".