commons configuration2를 사용하여 특정 파일 기반 속성이 변경되면 알림을 받으려합니다. 그 때문에 ReloadingFileBasedConfigurationBuilder, PeriodicReloadingTrigger를 사용하고 있습니다.아파치 commons configuration2 : ReloadingFileBasedConfigurationBuilder에 대한 ConfigurationEvent가 생성되지 않았습니다
문서에 따라 기본 파일이 변경 될 때 builder를 중앙 구성 요소로 사용하고 builder.getConfiguration()을 사용하여 구성을 재생성해야합니다. 파일이 변경되면 ConfigurationBuilderEvent.RESET 알림을 받고 새 구성으로 구성을 새로 고칠 수 있습니다.
그러나 ConfigurationEvent.ANY에 대한 이벤트 수신기를 추가하려고하면 변경된 파일의 실제 속성에 대한 알림을 받지만 알림을받지 못합니다. 어떤 도움을 주셔서 감사합니다.
import java.io.File;
import java.util.concurrent.TimeUnit;
import org.apache.commons.configuration2.PropertiesConfiguration;
import org.apache.commons.configuration2.builder.ConfigurationBuilderEvent;
import org.apache.commons.configuration2.builder.EventListenerParameters;
import org.apache.commons.configuration2.builder.ReloadingFileBasedConfigurationBuilder;
import org.apache.commons.configuration2.builder.fluent.Parameters;
import org.apache.commons.configuration2.event.ConfigurationEvent;
import org.apache.commons.configuration2.event.EventListener;
import org.apache.commons.configuration2.reloading.PeriodicReloadingTrigger;
public class ReloadingConfigEventTest {
public static void main(String[] args) throws Exception {
Parameters params = new Parameters();
EventListenerParameters listenerParams = new EventListenerParameters();
listenerParams.addEventListener(ConfigurationEvent.ANY, new EventListener<ConfigurationEvent>() {
public void onEvent(ConfigurationEvent event) {
System.out.println(event.getEventType().getName() +" "+event.getPropertyName());
}
}).addEventListener(ConfigurationBuilderEvent.RESET, new EventListener<ConfigurationBuilderEvent>() {
public void onEvent(ConfigurationBuilderEvent event) {
System.out.println("Event:" + event.getEventType().getName());
}
});
ReloadingFileBasedConfigurationBuilder<PropertiesConfiguration> builder = new ReloadingFileBasedConfigurationBuilder<PropertiesConfiguration>(
PropertiesConfiguration.class)
.configure(params.fileBased().setFile(new File("src/main/resource/override.conf")), listenerParams);
PeriodicReloadingTrigger trigger = new PeriodicReloadingTrigger(builder.getReloadingController(), null, 1,
TimeUnit.SECONDS);
trigger.start();
//modify the property file during the infinite loop, the new property is picked, but the SET_PROPERTY notification is missing
while (true) {
Thread.sleep(1000);
System.out.println(builder.getConfiguration().getString("test.property1"));
}
}
}