SpringBoot创建定时任务
2017-07-16 19:37
351 查看
之前总结过spring+quartz实现定时任务的整合http://www.cnblogs.com/gdpuzxs/p/6663725.html,而springboot创建定时任务则是相当简单。
(1)在springboot主类中@
(2)创建定时任务实现类,如下:
执行结果,如下:
(1)在springboot主类中@
EnableScheduling注解,启用定时任务的配置,如下:
(2)创建定时任务实现类,如下:
package springboot.web; import java.text.SimpleDateFormat; import java.util.Date; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @Component public class ScheduledTasks { private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); @Scheduled(cron="0 */1 * * * ?") public void reportCurrentTime() { System.out.println("每一分钟执行一次:" + dateFormat.format(new Date())); } }
执行结果,如下:
相关文章推荐
- spring-boot实战【09】【转】:Spring Boot中使用@Scheduled创建定时任务
- spring boot创建定时任务
- 详解SpringBoot 创建定时任务(配合数据库动态执行)
- Spring Boot中使用@Scheduled创建定时任务
- Spring Boot中使用@Scheduled创建定时任务
- Spring Boot中使用@Scheduled创建定时任务
- 详解Spring Boot中使用@Scheduled创建定时任务
- 【SpringBoot】——创建定时任务
- Spring Boot中使用@Scheduled创建定时任务
- SpringBoot使用@Scheduled创建定时任务
- SpringBoot入门系列篇(四):使用SpringBoot创建定时任务
- Spring Boot 计划任务(定时任务)
- springboot之定时任务
- spring-boot(五) RabbitMQ详解 定时任务
- Springboot整合mybatis及分页查询、定时任务)
- spring-boot通过@Scheduled配置定时任务及定时任务@Scheduled注解的方法
- spring boot环境下使用quartz设置定时任务
- Spring Boot定时任务实例
- 在Spring Boot中使用@Scheduled实现定时任务
- Spring Boot集成持久化Quartz定时任务管理和界面展示