commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Heger <>
Subject Re: [configuration] Unable to persist CombinedConfiguration changes to the Filesystem.
Date Sat, 22 Oct 2011 15:13:08 GMT
Am 21.10.2011 22:49, schrieb raghunath tpk:
> Hi,
> I am using apache commons configuration to load the configuration data from
> various sources.
> Following is the issue :
> I use a config.xml file to load multiple Configuration Sources
> Ex:
> <configuration>
> <header/>
> <override>
> <properties fileName=""/>
> <properties fileName=""/>
> <xml fileName="gui.xml"/>
> </override>
> <additional/>
> </configuration>
> I load the config.xml and subsequently all the properties in my app to a
> CombinedConfiguration Object as follows :
> DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
> builder.setFile(new File("config.xml"));
> CombinedConfiguration combinedConfig = builder.getConfiguration(true);
> Now I am trying to expose all the properties from all configuration sources
> using a mbean and at runtime trying to update the Properties. I wouldn't
> know though, from which source the properties came from as the
> CombinedConfiguration takes care of that abstraction, but when I do the
> following it doesn't change the persistance store(in this case the files on
> the Filesystem).
> /*combinedConfig.setProperty(Key, updatedValue);*/
> There is no save method on the combinedConfiguration class so that the
> persistance store gets updated.
> There is a save method in PropertiesConfiguration class or XMLConfiguration
> class, but I wouldn't know at runtime or inside the code which file or
> configuration source the Key belongs to, so even If I add a config-name to
> each source there is no use.
> SO wouldn't the setProperty help me update the value of the Configuration
> and persist it back to the original file. I don't know it is a bug or a
> feature it doesn't support or there is a workaround in such scenarios.
> Please advice.

If you pass an arbitrary key to the combined configuration in its 
setProperty() method, it cannot decide to which configuration source the 
key should be added. What exactly do you expect to happen?

I don't know whether this helps you for your current use case, but what 
you can do is copy the content of the whole CombinedConfiguration to a 
XMLConfiguration. Just use the constructor which expects a hierarchical 

XMLConfiguration newConfig = new XMLConfiguration(combinedConfiguration);

Now you can save the XMLConfiguration, but this file will contain all of 
the data, and the single configuration sources won't be updated.

The user guide [1] also contains some information about this topic.



> Thanks
> Raghu

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

View raw message