Spring Boot中的计划任务无法正常工作

时间:2018-11-12 15:35:24

标签: spring

我使用Spring Boot构建simpy Web api服务应用程序,并在Spring Boot中使用Scheduled任务创建了一些cron作业服务,但是无法正常工作。我需要在每个工作日[周一至周五]的12:00(当天)运行此服务。 这是一个出色的书架:@Scheduled(cron="0 1 1 ? * *")

2 个答案:

答案 0 :(得分:0)

确保在配置中包含@EnableScheduling:

@SpringBootApplication
@EnableScheduling
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class);
    }
}

Cron应该是

@Scheduled(cron = "0 0 0 * * MON-FRI")

好榜样here

答案 1 :(得分:0)

检查是否在配置类中添加了@EnableScheduling注释

@SpringBootApplication
@EnableScheduling
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class);
    }
}

选中此https://spring.io/guides/gs/scheduling-tasks/