commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Heger <oliver.he...@t-online.de>
Subject Re: Configuration: Loading multiple property files
Date Wed, 18 Jan 2006 19:41:04 GMT
Roshan Paiva wrote:

>Hi,
>
> 
>
>I need to be able to, 
>
>- load multiple property files
>
>- watch them for changes and 
>
>- have them reloaded if changed without a server restart.
>
> 
>
>I have done the following, however when I load multiple property files
>it seems to watch only the first file that was loaded (in this case it
>reloads message.properties and not email.properties). It would be great
>if you could let me know what I'm doing wrong, or if there is a better
>way of achieving the same.
>
> 
>
>            PropertiesConfiguration config = new
>PropertiesConfiguration();
>
> 
>
>            config.load("message.properties");
>
>            config.load("email.properties");
>
>            ...
>
>            config.setReloadingStrategy(new
>FileChangedReloadingStrategy());
>
> 
>
>I have also tried using a single property file with the other files
>defined inside that file (include=something.properties). In this case
>too, it doesn't seem to reload the other property files.
>
> 
>
>Thanks and Regards
>
>Roshan
>
> 
>
>
>  
>
A PropertiesConfiguration object can only be associated with a single
file. So if you want to monitor two different files, you also need two
configuration objects (and two reloading strategies).

In case you want to access the properties defined in the two files as a
single (logical) configuration object, you can use the
CompositeConfiguration class. This class acts like a container for
configuration objects. The following fragment shows how you can load the
two properties files and add the corresponding configuration objects to
a CompositeConfiguration:

PropertiesConfiguration conf1 = new
PropertiesConfiguration("message.properties");
conf1.setReloadingStrategy(new FileChangedReloadingStrategy());
PropertiesConfiguration conf2 = new
PropertiesConfiguration("email.properties");
conf2.setReloadingStrategy(new FileChangedReloadingStrategy());

CompositeConfiguration cc = new CompositeConfiguration();
cc.addConfiguration(conf1);
cc.addConfiguration(conf2);

// now cc can be used for accessing properties from both sources
String val1 = cc.getString("property.from.file1");
String val2 = cc.getString("property.from.file2");

Oliver

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message