PropertiesConfiguration不想重新加载

时间:2015-01-16 14:56:24

标签: java apache-commons-config

我想让我的属性文件每隔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中的属性。所以我的问题是:FileChangedReloadingStrategy是否调用了PropertiesConfiguration.load()方法?

1 个答案:

答案 0 :(得分:0)

确保您更改了部署目录中的文件而不是IDE中的源文件。