Search code examples
javaapache-commons-config

Loading updated properties automatically from multiple properties files


My requirement is to update the configurations of my application automatically when a change is made to a properties file.
For maintaining the properties, I am using PropertiesConfiguration from Apache Commons Configuration project.(Using commons-configuration-1.6.jar).
Using the FileChangedReloadingStrategy works well for a change made to a single properties file and is picked up by my application.

    PropertiesConfiguration config = new PropertiesConfiguration();
    config.load(new File("../test1.properties"));
    config.load(new File("../test2.properties"));
    config.setReloadingStrategy(new FileChangedReloadingStrategy());

But I am using multiple properties files using their load method and when any one of the properties file is updated I need to be able to detect the changes and automatically update the configuration in my project.
Is there a way to do this update using the FileChangedReloadingStrategy?
Or is there any other way you would suggest that I can make use of?


Solution

  • You can use a CompositeConfiguration to join two separate FileConfigurations, each with its own FileChangedReloadingStrategy.