SpringBoot - 定时任务 @EnableScheduling,@Scheduled

1.在启动类上添加@EnableScheduling注解,开启对定时任务的支持

//开启对定时任务的支持
@EnableScheduling
@SpringBootApplication
public class Learn20221218Application {
    public static void main(String[] args) {
        SpringApplication.run(Learn20221218Application.class, args);
    }
}

2.@Scheduled 注解,只能用在方法上

@Component
public class SchedulingService {
    @Scheduled(cron = "")
    public void scheduled(){

    }
}

cron 表达式生成器

posted on 2022-12-30 15:53  Mikasa-Ackerman  阅读(61)  评论(0编辑  收藏  举报

导航