Alex Rivera | Logout

How to configure a Spring beans with properties that are stored in a database table

Asked 2011-01-04T22:48:05.423
22

In my project we'd like to externalize the properties of our Spring managed beans, that is very easy to do with standard Java .properties files, however we want to be able to read those properties from a DB table that behaves like a Map (key is the property name, value is the value assigned to that property).

I found this post that suggest the usage of Commons Configuration but I don't know if there's a better way to do the same with Spring 3.x. Maybe implementing my own PropertyResource or something.

Any clues?

Edit
Report

1 Answer

0

There are ways to create "PropertyPlaceholderConfigurer" Programmatically , please see below.

Write a DAO which reads Properties and create a PropertyPlaceholderConfigurer as shown below.

XmlBeanFactory factory = new XmlBeanFactory(new FileSystemResource("beans.xml"));
PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
cfg.setProperties(yourProperties);
cfg.postProcessBeanFactory(factory);
answered 2012-07-01T19:18:01.943

Your Answer