之前总结过spring+quartz实现定时任务的整合http://www.cnblogs.com/gdpuzxs/p/6663725.html,而springboot创建定时任务则是相当简单。

  (1)在springboot主类中@EnableScheduling注解,启用定时任务的配置,如下:

  

  (2)创建定时任务实现类,如下:

  1. package springboot.web;
  2.  
  3. import java.text.SimpleDateFormat;
  4. import java.util.Date;
  5.  
  6. import org.springframework.scheduling.annotation.Scheduled;
  7. import org.springframework.stereotype.Component;
  8.  
  9. @Component
  10. public class ScheduledTasks {
  11.  
  12. private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
  13.  
  14. @Scheduled(cron="0 */1 * * * ?")
  15. public void reportCurrentTime() {
  16.  
  17. System.out.println("每一分钟执行一次:" + dateFormat.format(new Date()));
  18. }
  19.  
  20. }

  执行结果,如下:

  

SpringBoot创建定时任务的更多相关文章

  1. 四、springBoot 优雅的创建定时任务

    前言 好几天没写了,工作有点忙,最近工作刚好做一个定时任务统计的,所以就将springboot 如何创建定时任务整理了一下. 总的来说,springboot创建定时任务是非常简单的,不用像spring ...

  2. 玩转SpringBoot之定时任务详解

    序言 使用SpringBoot创建定时任务非常简单,目前主要有以下三种创建方式: 一.基于注解(@Scheduled) 二.基于接口(SchedulingConfigurer) 前者相信大家都很熟悉, ...

  3. 十三、springboot集成定时任务(Scheduling Tasks)

    定时任务(Scheduling Tasks) 在springboot创建定时任务比较简单,只需2步: 1.在程序的入口加上@EnableScheduling注解. 2.在定时方法上加@Schedule ...

  4. Springboot定时任务原理及如何动态创建定时任务

    一.前言 上周工作遇到了一个需求,同步多个省份销号数据,解绑微信粉丝.分省定时将销号数据放到SFTP服务器上,我需要开发定时任务去解析文件.因为是多省份,服务器.文件名规则.数据规则都不一定,所以要做 ...

  5. SpringBoot中使用@Scheduled创建定时任务

    SpringBoot中使用@Scheduled创建定时任务 定时任务一般会在很多项目中都会用到,我们往往会间隔性的的去完成某些特定任务来减少服务器和数据库的压力.比较常见的就是金融服务系统推送回调,一 ...

  6. 基于SpringBoot实现定时任务的设置(常用:定时清理数据库)

    1.构建SpringBoot工程项目 1)创建一个Springboot工程,在它的程序入口加上@EnableScheduling,开启调度任务. @SpringBootApplication @Ena ...

  7. ⑤SpringBoot之定时任务

    本文介绍SpringBoot定时任务的使用,springboot默认已经帮我们实行了,只需要添加相应的注解就可以实现. 1.pom配置文件 pom包里面只需要引入springboot starter包 ...

  8. springboot(八)-定时任务

    在我们的项目开发过程中,经常需要定时任务来帮助我们来做一些内容. 如果我们不用springboot开发的话,我们写定时任务需要写那些配置呢? 我们需要在application.xml文件中添加以下配置 ...

  9. SpringBoot 启动定时任务

    再项目中大多会使用定时任务来定时执行一些操作,如:文件迁移,备份等等.今天就来跟大家一起学习下如何在SpringBoot中创建定时任务. 1.新建SpringBoot项目,或在原有的项目上添加(不知道 ...

随机推荐

  1. Python 之 UUID

    UUID是根据MAC以及当前时间等创建的不重复的随机字符串 import uuid # Generate a UUID from a host ID, sequence number, and the ...

  2. 剑指Offer——表示数值的字符串

    题目描述: 请实现一个函数用来判断字符串是否表示数值(包括整数和小数).例如,字符串"+100","5e2","-123","3. ...

  3. Ignatius and the Princess IV---hdu1029(动态规划或者sort)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1029 就是给你n(n是奇数)个数找出个数大于(n+1)/ 2 的那个数: n的取值范围是 n(1< ...

  4. Django-vue之emement-ui,绑定图片,页面挂载,路由跳转

    一  emement-ui使用 首先在终端下载安装:npm install element-ui 在vue项目中的main.js下: import ElementUI from 'element-ui ...

  5. Oracle 实现拆分列数据的split()方法

    -- 创建需要划分的字符串 with T1 as( select 'one,two,three,four,five,six,seven,eight,nine,zero' as source_strin ...

  6. K-medodis聚类算法MATLAB

    国内博客,上介绍实现的K-medodis方法为: 与K-means算法类似.只是距离选择与聚类中心选择不同. 距离为曼哈顿距离 聚类中心选择为:依次把一个聚类中的每一个点当作当前类的聚类中心,求出代价 ...

  7. SonarQube+jenkins+maven平台搭建

    SonarQube代码质量管理 1.配置jdk和maven jenkins - 系统管理 - 全局工具配置 jdk安装: # which java# /usr/local/java/jdk1.8.0. ...

  8. xpath草稿

    (一)日期和简介 date:2017/12/18 name:a标签href属性提取抛出异常list index out of range (二)问题详细说明: 以百度新闻页面为例: 1.node_li ...

  9. 本书版权输出到台湾地区,《深入理解Android内核设计思想》诚挚感谢大家一直以来的支持!

  10. angular-file-upload

    <div id="page-title"> <h2 class="title-hero" ng-if="!isEdit"& ...