Reputation: 21
I'm using Apache commons-configurations2 (v2.10.1) to load app configs and reload some of the property files dynamically using a ReloadCombinedConfigrationBuilder, however the reload is not working.
Here is my configuration.xml
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<configuration>
<header>
<fileSystem config-class="org.apache.commons.configuration2.io.DefaultFileSystem"/>
<result>
<nodeCombiner config-class="org.apache.commons.configuration2.tree.OverrideCombiner"/>
<listDelimiterHandler config-class="org.apache.commons.configuration2.convert.DefaultListDelimiterHandler">
<config-constrarg config-value="|"/>
</listDelimiterHandler>
</result>
</header>
<override>
<system/>
<properties fileName="app1.properties" config-name="app1Properties" config-optional="true" config-reload="true" reloadingRefreshDelay="5000"/>
<properties fileName="bootstrap.properties"/>
</override>
</configuration>
Here is my code snippet.
Parameters params = new Parameters();
ReloadingCombinedConfigurationBuilder combinedBuilder =
new ReloadingCombinedConfigurationBuilder()
.configure(params.fileBased().setFileName("configuration.xml"));
// without this, the combinedBuilder.getReloadingController() is coming null and a NPE is thrown
combinedBuilder.getConfiguration();
// Register an event listener for triggering reloading checks
combinedBuilder.addEventListener(ConfigurationBuilderEvent.CONFIGURATION_REQUEST,
(EventListener) event -> combinedBuilder.getReloadingController().checkForReloading(null));
// apache guide suggests to have this line as well
combinedBuilder.getReloadingController().addEventListener(
ReloadingEvent.ANY, event -> event.getController().resetReloadingState());
PeriodicReloadingTrigger trigger = new PeriodicReloadingTrigger(combinedBuilder.getReloadingController(),
null, 60, TimeUnit.SECONDS);
trigger.start();
return combinedBuilder.getConfiguration();
Here is the app1.properties which I'm expecting to reload a changed property value.
server.host=api-dev.testserver.com
Appreciate your help.
I referred to the common-configurations2 guide and implemented steps as explained. I also verified on stackoverflow thread, but that didn't help
Upvotes: 0
Views: 54