commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From venkat veludandi <venkatveluda...@yahoo.com>
Subject Commons Configuration: Using Reload Strategy
Date Sun, 15 May 2011 22:56:27 GMT
Good afternoon.
I am using commons configuration as follows:
 
commons_configuration.xml:
 
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <properties fileName="test.properties" config-name="test">
   <reloadingStrategy refreshDelay="30000"
     config-class="org.apache.commons.configuration.reloading.FileChangedReloadingStrategy"/>
  </properties>
</configuration>
 
===============================================
CommonsConfiguration.java
----------------------------------------
 
public class CommonsConfiguration {
 
 
 private static CombinedConfiguration configuration;
 
 
 static {
  try {
   DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(new File("/var/commons_configuration.xml"));
   configuration = builder.getConfiguration(true);
  } catch (ConfigurationException e) {
   e.printStackTrace();
  }
 }
 
 
 public static CombinedConfiguration getCombinedConfiguration() {
  return configuration;
 }
}
=================================================================
When I use commons configuration as follows in any instance/static method:
 
String testMe= (String) CommonsConfiguration.getCombinedConfiguration().getConfiguration("test").getProperty("test.me");
 
It work fine with reloading strategy. In other words when I change the test.properties property
value, the change gets reflected.
 
In some class I was accessing the property in a static block as follows:
public Sample {
 static{
  String testMe = String) CommonsConfiguration.getCombinedConfiguration().getConfiguration("test").getProperty("test.me");
  //do something
 }
}
 
If a property is accessed in static block and the property value is changed, the change does
not get reflected.
Is there any work around to access a property in static block and have the property change
reflected.
 
I appreciate and thank you for your feed back.
 
Thanks
Venkat

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message