Spring框架實現定時任務排程

2021-09-13 21:29:43 字數 968 閱讀 5958

在spring配置檔案中進行配置基本資訊

在xmlns中新增

xmlns:task=""

在xsi中新增

/spring-task-3.2.xsd

然後是必須的一項,因為這個是spring提供的定時任務,所以需要進行掃瞄類下的包才能執行相應的操作

然後是設定定時任務

開始在測試類中寫測試**

import org.springframework.scheduling.annotation.scheduled;

import org.springframework.stereotype.component;

/*** created by leo on 2018/1/22.

*/@component

public class timertask

}cron配置

cron表示式 含義 

「0 0 12 * * ?」 每天中午十二點觸發 

「0 15 10 ? * *」 每天早上10:15觸發 

「0 15 10 * * ?」 每天早上10:15觸發 

「0 15 10 * * ? *」 每天早上10:15觸發 

「0 15 10 * * ? 2005」 2023年的每天早上10:15觸發 

「0 * 14 * * ?」 每天從下午2點開始到2點59分每分鐘一次觸發 

「0 0/5 14 * * ?」 每天從下午2點開始到2:55分結束每5分鐘一次觸發 

「0 0/5 14,18 * * ?」 每天的下午2點至2:55和6點至6點55分兩個時間段內每5分鐘一次觸發 

「0 0-5 14 * * ?」 每天14:00至14:05每分鐘一次觸發 

「0 10,44 14 ? 3 wed」 三月的每週三的14:10和14:44觸發 

「0 15 10 ? * mon-fri」 每個周

一、周二、周

三、周四、周五的10:15觸發

spring 實現定時任務demo

controller public class signininfotask catch exception e xmlns xmlns xsi xmlns p xmlns aop xmlns context xmlns jee xmlns tx xmlns task xsi schemalocat...

Spring實現定時任務排程

spring的配置 要定時執行的方法 public class hellotask 測試類 public static void main string args cronexpression的配置 字段 允許值 允許的特殊字元 秒 0 59 分 0 59 小時 0 23 日期 1 31 l w c...

Spring定時任務實現

一 spring 定時任務 component enablescheduling 可以在啟動類上註解也可以在當前檔案 public class testschedule scheduled fixedrate 1000 10 public void runsecend scheduled fixed...