Springboot定时任务
- 开启定时任务支持 @EnableScheduling
@EnableScheduling // ①:开启定时功能
@SpringBootApplication
@ComponentScan("com.carter") // 开启扫描
public class DemoApplication {
// 启动按钮
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
- 进行注解配置 @Scheduled
/**
*②:开启方法定时
* 秒 分 时 日 月 周
*/
@Scheduled(cron="*/2 * * * * ?")
public void hello(){
System.out.println("hello,小Carter,你执行了哦!!!");
}
本文详细介绍了如何在SpringBoot项目中使用@EnableScheduling和@Scheduled注解来实现定时任务。通过示例代码展示了如何配置定时任务,以及如何设置任务的执行频率。
762

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



