Spring Boot入门教程-定时任务
来源:互联网 发布:淘宝外卖和口碑的区别 编辑:程序博客网 时间:2024/05/23 01:25
说到定时任务,用到最多的就是quartz,当然早spring 中使用quartz 也是需要一堆配置的,但是在Spring Boot 中定时任务同样带给我们惊喜。
1.创建一个定时任务类ScheduledTasks 并添加以下注解
@Component@Configurable@EnableScheduling
@EnableScheduled 这个注解表是这个类为定时任务类类
2.编写一个方法 并添加@scheduled注解//每1分钟执行一次 @Scheduled(cron = "0 */1 * * * * ") public void reportCurrentByCron(){ System.out.println ("定时任务启动: " + dateFormat ().format (new Date())); } private SimpleDateFormat dateFormat(){ return new SimpleDateFormat ("HH:mm:ss"); }@scheduled 注解括号中是Cron表达式
全部代码为:
@Component@Configurable@EnableSchedulingpublic class ScheduledTasks { //每1分钟执行一次 @Scheduled(cron = "0 */1 * * * * ") public void reportCurrentByCron(){ System.out.println ("定时任务启动: " + dateFormat ().format (new Date())); } private SimpleDateFormat dateFormat(){ return new SimpleDateFormat ("HH:mm:ss"); }}3.启动后控制台信息:
定时任务就完成了。
阅读全文
0 0
- Spring Boot入门教程-定时任务
- spring boot 定时任务
- spring boot 定时任务
- spring boot定时任务
- Spring boot 定时任务
- Spring Boot 定时任务
- Spring Boot 实现定时任务
- spring boot创建定时任务
- Spring Boot定时任务实例
- 【Spring Boot】定时任务实现
- Spring Boot 实现定时任务
- spring boot实现定时任务
- Spring Boot : 定时任务(十)
- Spring Boot 实现定时任务
- Spring Boot 配置定时任务
- Spring boot 十 定时任务
- spring-boot集成定时任务
- Spring Boot 计划任务(定时任务)
- jsoup爬虫简单使用笔记
- 保持 RAC 群集环境稳定当前必须要做的 11 件事 (文档 ID 1525819.1)
- opengl中将三维坐标转换到屏幕坐标
- POJ2413 How many Fibs(高精度)(AC)
- MySQL
- Spring Boot入门教程-定时任务
- idea下载安装破解详解
- GDI+接口使用说明
- 判断IP地址是否为公有地址
- java自定义分页标签
- 【Linux】NAT模式下关于主机ping不通虚拟机的问题
- 北大方正,前景不妙!
- Java 使用Builder解决构造函数参数过多的问题
- java成员变量修饰符