我想让我的属性文件每 xx 秒重新加载一次。我的代码:
...
configuration = new PropertiesConfiguration();
configuration.setFileName(filename);
if (configuration.getFile().exists()) {
configuration.load();
final FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy();
strategy.setRefreshDelay(3000);
configuration.setReloadingStrategy(strategy);
} else {
LOGGER.warn("Configuration file '{}' not found", filename);
}
...
但是我的文件永远不会重新加载:(有什么想法吗?
编辑:实际上我认为我的问题来自我覆盖 load() 方法的事实:
private static final class SystemPropertiesConfiguration extends PropertiesConfiguration {
public SystemPropertiesConfiguration(String fileName) throws ConfigurationException
{
super(fileName);
}
@Override
public synchronized void load(final Reader in) throws ConfigurationException {
super.load(in);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Updating system properties");
}
final boolean debugEnabled = LOGGER.isDebugEnabled();
final Iterator<String> ite = getKeys();
String key;
while (ite.hasNext()) {
key = ite.next();
if (debugEnabled) {
LOGGER.debug("Updating system property: {}", key);
}
System.setProperty(key, getString(key));
}
}
}
目的实际上是推送 System.properties 中的属性。所以我的问题是: FileChangedReloadingStrategy 是否调用 PropertiesConfiguration.load() 方法?