Using Apache Commons Configuration

Frequently applications need to have different settings between development, staging, and production environments.  Usually there are default settings stored with in source control, but when it comes time to deploy to one of your environments you want to override these defaults with environment specific settings.  For certain properties you might also need to modify them while the appliction is running, which can get be become problematic if you have to restart your application server every time you change a property.  

A way to avoid this in Java is by using Apache Commons Configuration which provides:

 1) Property Overriding - Depending upon how you define the order your property files are ordered in your xml config file, a property can be override.  

 2) Dynamically Reload Properties - Commons configuration will watch files for modifications and automatically load any changes that are made.  

To get overriding behavior use OverrideCombiner in your configuration file, and the define your properties in descending order of precedence: 

https://gist.github.com/895145

Finally, in your code wrap your configuration in a property manager class that makes use of the CombinedConfiguration class:

http://gist.github.com/892377