I have just released a small open-source project onto google code called MaduraConfiguration.

MaduraConfiguration is for those times when you want to distribute a packaged up application in a jar file, war file etc but you want to enable the deployer to configure it using an external file. Apache Commons Configuration (ACC) did a good job of this already so MaduraConfiguration uses that, but it adds the ability to wire (or inject) the configuration information directly into Spring beans. This is done with various factories which deliver various data types, including JDom Documents and List<String>.

In practice you just write Java beans as normal and then wire them just a little differently. Then you write an ACC XML file (ACC supports various formats but XML is the only one we actually use). If you are deploying on an application server you probably want to use a JNDI reference to find the file. This is easy with Spring. If you want you can wire it so that if the config file changes everything reloads, or you can trigger it using JMX. The reload is all part of ACC, except for the Spring bit.

Yes, I do know that you can define a properties file and tell Spring to use the values from it. But XML is richer than properties and the reload stuff is useful. There are also events triggered by ACC that you can add listeners for.

Edit: I’ve moved this to a maven project on github.

Leave a Reply

Your email address will not be published. Required fields are marked *