spring boot 定时任务
1. 在主入口加注解:@EnableScheduling
@EnableScheduling
@SpringBootApplication
public class TipApplication {
public static void main(String[] args) {
SpringApplication.run(TipApplication.class, args);
}
}
2. 新建 task 类,类上使用注解:@Component,方法上使用注解:@Scheduled
@Component
public class TipTask {
// @Scheduled(fixedRate = 3000)
// 每3秒执行一次
// 秒 分钟 小时 日 月 星期 年(不支持)
// http://cron.qqe2.com/
// 每3分钟执行一次
@Scheduled(cron = "0 */3 * * * ?")
public void tip() {
// syso
}
}
浙公网安备 33010602011771号