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(){ } }标签:Scheduled,SpringBoot,public,cron,EnableScheduling,定时,class From: https://www.cnblogs.com/ErenYeager/p/17015105.html