定时器注解

//1.在启动main方法上添加@EnableScheduling注解,表示开启定时任务
@SpringBootApplication
@EnableScheduling
public class LjSysManageApplication {
public static void main(String[] args) {
SpringApplication.run(LjSysManageApplication.class, args);
}
}

//2.编写定时任务
@Component
public class SchedulerTask {
@Autowired
SchedulerTaskService schedulerService;
/**
* 表示每天0点执行一次
*/
@Scheduled(cron = "0 0 0 * * ?")
/**
* 表示每5秒执行一次
*
*/
//@Scheduled(cron = "*/5 * * * * ?")
private ResponseHelper getYear(){
return schedulerService.GetYear();
}
}


猜你喜欢

转载自www.cnblogs.com/qkkdemo/p/12214965.html
今日推荐