Persistable bean values in Spring BeanFactory

I was thinking if the following scenario could be achieved in Spring BeanFactory:

  • use property placeholders inside the definitions ( i mean ${prop.value})
  • apply programmatically a PropertyPlaceholderConfigurer to obtain the real values and retrieve the beans
  • apply another PropertyPlaceholderConfigurer and obtain another set of beans

Actually this behavior is not available. After applying the first PropertyPlaceholderConfigurer the values ${prop.value} are lost foreever, so applying another PropertyPlaceholderConfigurer will do nothing in fact.
The solution I see for solving this are:

  • either clone in a way the BeanFactory and apply PropertyPlaceholderConfigurer on the clone (till this moment I couldn’t figure out a way to implement this)
  • or create a custom BeanFactory (probably by extending DefaultListableBeanFactory) that will be able to keep the original values after applying a property placeholder

Does anybody see any other solution for this?

2 Comments

Filed under Uncategorized

2 responses to “Persistable bean values in Spring BeanFactory

  1. Anonymous

    Hey Pope,

    You should be able to write some form of custom post processor that manages this information for you – maybe use something OTHER than the built in post processors. I’m not 100% sure I understand the intended result, but it sounds like you want to go through 2 entire processing cycles (e.g. two bean definition instantiation cycles), which may be problematic with one bean factory; another option is to wrap the beans in target sources or something of that nature… I’ll think about this more.

  2. Shameer Kunjumohamed

    Have you ever thaught of a BeanFactory capable of reading bean definition (XML) files from a database table, so that we can easily modify bean definitions and refresh the BeanFactory without redeploying the application ?

    I could not find a readily implemented one, so I am planning to develop it myself. Any ideas or pointers appreciated

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s