I’d like to extend/replace the Spring PropertyPlaceholderConfigurer to read from a web server as opposed to properties files.
A bit of background:
I work on a project, and we’re finding the number of properties files located on the users systems is getting a little unwieldy. We’d like to replace these files with a ‘config server’ which will store basic key/value pairs and serve them when the user starts up the app.
To avoid making too many changes, I’d like to change the way the PropertyPlaceholderConfigurer finds properties – rather than implementing an entirely new way to manage properties. So on startup – Spring will read all properties from a url, and feed these into my spring config xml in the same way as it would have with actual files.
Bonus!
If anyone has any ideas how to do this where properties are reloaded from the server only when they change, will get bonus points (I have no idea if I have the ability to assign bonus points, but I’ll try!). That would be a ‘nice to have, if there’s not too much effort involved’ solution.
Spring’s
PropertyPlaceholderConfigurer(PPC) already uses theResourceinterface to specfiy the location from where to read properties (via thesetLocation(Resource)method inherited from PropertiesLoaderSupport.There is an implementing class of this interface called
URLResourcewhich probably does what you want. You could simply create a PPC and set thelocationproperty with a bean of this type to load the properties from a URL instead of a file. This class also supportsfile://type URLs, so you could switch between on- and offline properties loading depending on the URL you use.