jump to navigation

Spring and PropertyPlaceholderConfigurers October 22, 2008

Posted by Phill in Spring.
Tags: , , , ,
comments closed

The project I’m currently working on is a fairly modular web app. We have an application context file for each module. This has worked pretty well so far. However, I ran into an issue today when I wanted to add a new module: I kept getting the issue ‘Could not resolve placeholder ‘(property name)’.

I thought this was a bit strange because I thought I’d set up the property configurer correctly, and the properties file was definitely in the right place.

It turns out (via a bit of Googling – see this thread) that you don’t need multiple PropertyPlaceholderConfigurers. If one is defined, it will load properties for the whole of your application context files (as long as they’re within the same overall context).

If you have multiple PropertyPlaceholderConfigurers defined, what will happen is that if one of them can’t find a specific property, it will treat it as a fatal exception. This is of course going to happen if your different configurers point to different properties files!

There are three solutions:

  • Set the “ignoreUnresolvablePlaceholders” attribute on all property placeholder;
  • Set the “placeholderPrefix” or “placeholderSuffix” properties individually for each one so they don’t all match ${…}
  • Use one property placeholder configurer and just point it to all your properties files.

I’ve gone with the last option at the moment – it’s the best solution for what we need at the moment.


Reloadable properties in Spring July 31, 2007

Posted by Phill in Spring.
Tags: , ,
comments closed

One of the issues I faced last week was to do with properties, specifically property reloading: in Spring, if you use something like PropertyPlaceholderConfigurer, the properties get set when the ApplicationContext loads up but then nothing happens when the properties change (even if you use the reloadable resource bundle).

This is only really a problem if you want to (for example) change a timeout value in the properties file. You can change it all you want, but if that value was dependency-injected via the PropertyPlaceholderConfigurer than you’re out of luck!

I was going to try and come up with a solution for this, but fortunately it seems that someone already has. I haven’t tested it yet, but it looks like it will do the job rather nicely.