//1.在启动main方法上添加@EnableScheduling注解,表示开启定时任务
@SpringBootApplication@EnableSchedulingpublic class LjSysManageApplication { public static void main(String[] args) { SpringApplication.run(LjSysManageApplication.class, args); }}//2.编写定时任务
@Componentpublic class SchedulerTask { @Autowired SchedulerTaskService schedulerService; /** * 表示每天0点执行一次 */ @Scheduled(cron = "0 0 0 * * ?") /** * 表示每5秒执行一次 * */ //@Scheduled(cron = "*/5 * * * * ?") private ResponseHelper getYear(){ return schedulerService.GetYear(); }}
来源:https://www.cnblogs.com/qkkdemo/p/12214965.html