今天在專案中需要用到乙個定時任務的功能,專案使用的框架是springboot,在此記錄一下再springboot中使用定時任務的一種方式,也希望能幫到有需要的小夥伴。
第一步:新增依賴
org.springframework.boot
spring-boot-starter-quartz
org.mybatis.spring.boot
mybatis-spring-boot-starter
1.2.0
第二步:在啟動類上註解
@enablescheduling //開啟定時任務支援
public static void main(string args) }
第三步:編寫定時任務類
@component
public class quartztask
//業務方法
private void mytaskjob()
需要注意的就是定時任務的時間設定,不清楚的問問度娘。
SpringBoot 定時任務
第一步 在啟動類中加入如下註解 enablescheduling public class public static void main string args 注意 enablescheduling必須加,否則無法開啟定時任務 第二步 建立定時任務 component public class ...
Spring boot定時任務
最近做專案,需要使用定時任務,半個小時去更新redis資料,於是便學習了一下經驗。希望可以幫到你們。定時任務可使用三種 created by fx on 2017 9 4.component allargsconstructor public class featuredatatask 實現乙個任務...
Spring boot 定時任務
1.在啟動類上加 enablescheduling註解 package com.example.demo import org.springframework.scheduling.annotation.enablescheduling enablescheduling public static ...