commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Santhosh Kumar <>
Subject RE: [Configuration] Environment Awareness in Configuration
Date Sun, 25 Apr 2010 21:07:44 GMT
Hi Oliver,

Thanks for the reply. While that solution works but user would need to maintain multiple properties
files at the risk of not keeping all of them in sync. Also that solution doesn't allow to
have a common properties along-with environment specific properties elegantly (but is possible
using include statement to a common properties).

My thought was to suffix the property with an environment specific string. At runtime specify
which environment server is running in (Let's say "server.env" system variable). Depending
of the value of this system property, this Configuration object would return the environment
specific value (if defined, else the default value).

For example, if we want to have database related properties, here is what it would look like.

databaseURL.stg = jdbc:oracle:stg-url
databaseURL.prd = jdbc:oracle:prd-url


databasePassword.prd = passwordprd

When application requests for a property (let's say databaseURL), this configuration object
would first suffix that with specified environment string (using server.env system parameter)
and try to get the value for "<key>.<environment string>". If The value present,
it would return the value. If value not defined, then it would look up the value for just

See the attached sample code I have written and been using it successfully in our projects.


-----Original Message-----
From: Oliver Heger [] 
Sent: Saturday, April 24, 2010 12:18 AM
To: Commons Developers List
Subject: Re: [Configuration] Environment Awareness in Configuration

Am 23.04.2010 20:36, schrieb Santhosh Kumar:
> It is a very common requirement that some configuration value changes across environments
(dev/qa/stg/prd etc). I went through the documentation but didn't find any feature to do this
in the Configuration (please correct me if you know a way to do this).
> If such feature doesn't already there, I was hoping something like EnvironmentAwareConfiguration
can add such feature based on the environment and server id (for usecases where each server
in the production cluster needs to get different property value).
> Please let me know what you think. If this is something adds value (which I truly believe
it will), I will post a detailed information.
> Thanks,
> Santhosh.

One way to achieve this would be to use DefaultConfigurationBuilder and 
the interpolation facilities supported by all configuration 
implementations. For instance, you can have the following definition 
file for DefaultConfigurationBuilder:

   <properties fileName="${env:STAGE}/"/>

Here with ${env:STAGE} the OS environment variable STAGE is referenced, 
and the properties file is load from a subdirectory whose name matches 
the value of the variable. The environment variable could have different 
values depending on the specific server environment and thus different 
configuration files would be loaded.

Note however, that interpolation of environment variables is available 
in Commons Configuration 1.7 only which has not yet been released.

Would this approach work for you?


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message