【问题标题】:Simple Netflix Archaius dynamic configuration example does not work with local files简单的 Netflix Archaius 动态配置示例不适用于本地文件
【发布时间】:2018-11-21 07:26:22
【问题描述】:
public static void main(String[] args) throws InterruptedException {
    DynamicStringProperty property = DynamicPropertyFactory.getInstance().getStringProperty("prop", "test");
    while (true) {
        System.out.println(property.get());
        Thread.sleep(2000);
    }
}

这是我在一个非常简单的测试文件中的代码。当我手动更改关联的 config.properties 文件中的属性时,更改不会在运行时反映。请告知我是否做错了什么?

【问题讨论】:

    标签: netflix-archaius


    【解决方案1】:

    在使用动态属性工厂之前调用以下函数:

    private static void Configure(){
    
          String url = null;
          try {
             url = new File("src/test/resources/config.properties").toURI().toURL().toString();
          } catch (MalformedURLException e) {
             e.printStackTrace();
          }
          DynamicURLConfiguration dynamicURLConfiguration = new DynamicURLConfiguration(1, 50, false,
                  url);
          ConcurrentCompositeConfiguration finalConfig = new ConcurrentCompositeConfiguration();
          finalConfig.addConfiguration(dynamicURLConfiguration, "fileConfig");
          ConfigurationManager.install(finalConfig);
       }
    

    【讨论】:

      猜你喜欢
      • 2016-06-13
      • 1970-01-01
      • 1970-01-01
      • 2023-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多