Spring 2.0 Property Reloading

Here’s an updated version of the net.wuenschenswert.spring property reloading package that works with Spring 2.0.x. The last version I posted was developed for Spring 1.2.8, and as it turns out, spring 2.0 has an incompatible change to the PropertyPlaceholderConfigurer super class. So now this code runs with spring 2.0 only. sigh.


9 thoughts on “Spring 2.0 Property Reloading”

  1. This is fantastic stuff, I’m amazed that Spring haven’t incorporated something like this into the framework, it seems like a no-brainer to me as this is something I’ve wanted for ages, and by reading their forums I am not alone. The “default values for properties” that you implemented is excellent too. Have you tried submitting this to them?

    I am using this on Spring 2.5.4 and it works a treat, thanks so much!

  2. This is exactly what I needed. We have an application in production and needed to go through a massive change control process to fix one typo because we need to bounce the box. Now we will never need to!

    Works really well with no code changes as you say. Nice work. I have given you full credit in the code.

    Have you had any word from the Spring folks about getting this in the Spring distribution? It would be very valuable for the community

    Thanks again,

  3. Great job,
    Works perfectly for simple use cases, but you quickly hit the limits.
    In fact we’re trying to use reloadable properties in lists and maps (doesn’t work) Doesn’t work also in nested bean definitions. And maybe other cases spring namespaces for instance (haven’t tested that).

    Have you thought about those cases? Do you have some work done for it?

  4. Thanks for this code, which does just what we need.

    In Spring 3 this no longer works as it stands because the createInstance hook has been removed from PropertiesFactoryBean – instead mergeProperties is called directly. You can get it working again by updating ReloadablePropertiesFactoryBean – declare a boolean initialised flag and change the createInstance method to:

    protected Properties mergeProperties() throws IOException {
    if (!initialised) {
    initialised = true;
    // would like to uninherit from AbstractFactoryBean (but it’s final!)
    if (!isSingleton())
    throw new RuntimeException(“ReloadablePropertiesFactoryBean only works as singleton”);
    reloadableProperties = new ReloadablePropertiesImpl();
    if (preListeners != null)
    return reloadableProperties;
    } else {
    return super.mergeProperties();

    I am just testing this at the moment, so will let you know if I hit problems

  5. Thanks for posting this solution. I agree with the other comments, sure would be handy to have this built into Spring itself. Sure there are lots of little issues to solve (Collections, potential inconsistent state of beans, etc.), but there is big upside too.

    I’m also in Spring 3 and I found Chris Gilbert’s comment above very helpful (thanks Chris!). But I was stumped on one part and I thought I would offer this clarification: REPLACE the ReloadablePropertiesFactoryBean.createInstance() method with Chris’s ReloadablePropertiesFactoryBean.mergeProperties() method.

    Another tip: the Task Scheduling in spring has changed quite a bit, and the entries in “dynamic.xml” are obsolete. You can simplify it with the following XML:

    …of course this presumes the task namespace is defined:


  6. OOoops! Can’t post XML. Let’s see if this works:

    <beans xmlns=”http://www.springframework.org/schema/beans”

    <!– Fire reloader every second. If no reloading needed, none will happen. –>
    <task:scheduled-tasks >
    <task:scheduled ref=”reloader” method=”run” fixed-delay=”1000″/>

Leave a Reply