Spring Schedule

时间:2020-04-28
本文章向大家介绍Spring Schedule,主要包括Spring Schedule使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

1.Spring Schedule Cron表达式:

  ①格式:秒 分 时 日 月 周 年(可选)

  ②

2.Spring Schedule配置

  ①.xml文件 : <task:annotation-driven/>

  ②定时任务类注解:@Component:

  ③定时任务方法注解:@Scheduled(cron = "0 */1 * * * ?")

 1 @Component
 2 public class Task {
 3 
 4     @Scheduled(cron = " * 0/2 * * * *")
 5     public void testSchedule(){
 6         System.out.println("定时任务测试开始");
 7         //TODO 业务逻辑
 8         System.out.println("定时任务测试结束");
 9     }
10 
11 }
12   
1 <?xml version="1.0" encoding="UTF-8"?>
2 <beans xmlns="http://www.springframework.org/schema/beans"
3        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:task="http://www.springframework.org/schema/task"
4        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd">
5 
6     <task:annotation-driven></task:annotation-driven>
7 </beans>

原文地址:https://www.cnblogs.com/BenNiaoXianFei/p/12794774.html