【问题标题】:PropertiesConfiguration doesn't want to reloadPropertiesConfiguration 不想重新加载
【发布时间】:2015-01-16 14:56:24
【问题描述】:

我想让我的属性文件每 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() 方法吗?

【问题讨论】:

  • 您希望配置何时重新加载?据我所知,它仅在通过检查文件是否修改来读取它时才会重新加载
  • 好吧,我已经修改了文件,我已经将 refreshDelay 设置为 3000,我希望它在重新加载时停止到我的断点,但它永远不会发生
  • 澄清一点:LOGGER 从未使用过,您只是看不到应用程序中的属性每 3 秒更改一次吗?
  • 嗯,是的,如果我删除属性文件,我会收到消息。但无论如何,是的,永远不会重新加载属性文件
  • 好吧,我会希望如果你删除它,它会抛出它哈哈。我的意思是如果文件在那里,但感谢您的回答。

标签: java apache-commons-config


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-26
    • 2020-09-08
    • 2017-08-11
    • 1970-01-01
    • 1970-01-01
    • 2012-06-15
    • 2011-07-21
    相关资源
    最近更新 更多