定时器注解

狂风中的少年 提交于 2020-01-19 18:53:33
//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();    }}

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!