1.在springboot主启动类上添加@EnableScheduling注解
@EnableScheduling
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
创建一个在类中写一个方法加上@Scheduled(cron = “”)注解并配合cron表达式即可
@Scheduled(cron = "*/5 * * * * ?")
public void tset01() {
System.out.println("111111");
}
ok
本文介绍了如何在SpringBoot应用中启用定时任务@EnableScheduling,并通过@Scheduled注解结合cron表达式来创建周期性执行的方法,例如每5分钟执行一次打印操作。
4165

被折叠的 条评论
为什么被折叠?



