문제

I have a configuration file (an XML) which I load using XMLConfiguration.

I need to make sure that this XMLConfiguration instance is updated ( every 30 seconds ).

For that matter I have the following code:

 XMLConfiguration configuration = new XMLConfiguration(configFile);
 configuration.setAutoSave(true);

 FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy();
 strategy.setRefreshDelay(getRefreshDelay());
 configuration.setReloadingStrategy(strategy);

It works great, but the thing is I want to log any changes in this XML file.

Is there a way of doing it?

도움이 되었습니까?

해결책

I got it!

All I need to do is this:

        ConfigurationListener listener = new ConfigurationListener() {

        @Override
        public void configurationChanged(ConfigurationEvent event) {
            if ( !event.isBeforeUpdate() ){
                System.out.println(event.getPropertyName() + " " + event.getPropertyValue());
            }
        }
    };
    configuration.addConfigurationListener(listener);

It works!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top