Я использую SpringBoot, чтобы следить за папкой на предмет новых файлов. Конфигурация выглядит так:
@Configuration
@ManagedResource
public class FileWatcherConfig {
Logger log = LoggerFactory.getLogger(FileWatcherConfig.class);
@Value("${filewatcher.path:C:\\test}")
String pathname;
@Bean
public FileSystemWatcher fileSystemWatcher() {
FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(true, Duration.ofMillis(5000L), Duration.ofMillis(3000L));
fileSystemWatcher.addSourceDirectory(new File(pathname));
fileSystemWatcher.addListener(new MyFileChangeListener());
fileSystemWatcher.start();
log.info("started fileSystemWatcher");
return fileSystemWatcher;
}
@PreDestroy
public void onDestroy() {
fileSystemWatcher().stop();
}
@ManagedOperation
public void setPathname(String pathname) {
this.pathname = pathname;
}
@ManagedAttribute
public String getPathname(){
return pathname;
}
}
Хотя я могу изменить значение пути во время выполнения с помощью jconsole, приложение по-прежнему отслеживает исходную папку.