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,你执行了哦!!!");
}