From where to run a FileWatcher on a project with spring-boot?

1

I already have a fileWatcher running with WatchService, it executes a task when a file is added to a predefined folder in the properties of the application. However I do not know which is the best site in the application to place it. Currently I left it in the main, but I do not think I should leave it there.

@SpringBootApplication
@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class })
public class MyApplication {

    @Value("${routing.folder}")
    private static String ROUTING_FOLDER;

    public static void main(String[] args) throws IOException {
        SpringApplication.run(MyApplication.class, args);
        Path dir = Paths.get(ROUTING_FOLDER);
        new SepaRoutingFilesWatcher(dir).processEvents();
    }

}

The class SepaRoutingFilesWatcher receives the location of the folder and keeps listening to the files added to it. I thought I can create a Job with @EnableBatchProcessing that launches the function when the application is executed, however I would like to do it in a cleaner way, for example from maven.

    
asked by AndreFontaine 21.03.2018 в 14:03
source

0 answers