cloudnaut
cloudnaut

Reputation: 982

Write a custom PlaceholderResolver in Spring (like PropertyPlaceholderConfigurerResolver)

I am using MBeans in an web application for application properties which a lot of people normally put in property files. The MBeans will be written and read from a database for persistence.

I am looking for a way of exposing my application properties (from the (m)beans to Spring (e.g. Spring EL, applicationContext.xml). In a lot of applications the PropertyPlaceholderConfigurerResolver is used but since I am only having a regular (m)Bean I want to expose the bean properties to spring expression language.

I have looked at PropertyPlaceholderConfigurerResolver to see how the properties are exposed to Spring Expression Language, but I don't see how.

I think somehow I need to write a custom PlaceholderResolver which accesses my MBeans. I have been googleing now for hours, so I would appreciate a hint :)

Regards

Upvotes: 3

Views: 1060

Answers (1)

dnc253
dnc253

Reputation: 40337

I'm not familiar with MBeans, but our application is getting application settings out of a database and then using them in our application context. We are just extending PropertySourcesPlaceholderConfigurer and then you just need to call the setPropertySources() method. In our constructor, we have something like this:

MutablePropertySources propertySources = new MutablePropertySources();
Map<String, Object> propertiesFromDB = getPropertiesFromDB();
MapPropertySource propertySource = new MapPropertySource("propsFromDB", propertiesFromDB);
propertySources.addFirst(propertySource);
setPropertySources(propertySources);

Upvotes: 2

Related Questions