How to add new schedule job dynamically with Spring

后端 未结 3 533
别跟我提以往
别跟我提以往 2020-12-13 05:49

I am writing a Spring Boot App

My requirements are - In the resources (src/main/resources) folder if I add new xml files.. I should read those files and get some ur

3条回答
  •  旧巷少年郎
    2020-12-13 05:58

    You can do that over a spring annotation:

    @Scheduled(fixedRate = 360000)
    public void parseXmlFile() {
        // logic for parsing the XML file.
    }
    

    Please note that the method must be void. Furthermore, in your main class, you must enable scheduling:

    @SpringBootApplication
    @EnableScheduling
    public class Application {
    
        public static void main(String[] args) throws Exception {
            SpringApplication.run(Application.class);
        }
    }
    

    Please see the full reference here: https://spring.io/guides/gs/scheduling-tasks/

提交回复
热议问题