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文件中的属性时,更改不会在运行时反映。请告知我做错了什么?
答案 0 :(得分:0)
在使用动态属性工厂之前调用以下函数:
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);
}