SprinBoot整合Quart实现定时调度
Quartz是一款开源的定时任务调度框架,Quartz的官网是:http://www.quartz-scheduler.org/。本文主要是讲诉使用springboot整合quartz实现定时任务调度管理的用例。主要的内容有如下三部分:
1. springboot整合quartz的相关配置
2. 实现基于simpleTrigger的定时任务
3. 实现基于cronTrigger的定时任务
一、导入相关的pom依赖
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.bruce.quartz.springboot.demo</groupId>
<artifactId>Quartz-SpringBoot-0426</artifactId>
<version>1.0-SNAPSHOT</version>
<!--导入SpringBoot-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
<relativePath />
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--Quartz任务调度的包 -->
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz-jobs</artifactId>
<version>2.2.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
二、创建SpringBoot的启动类
package com.anhong;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
/**
* @BelongsProject: Quartz-SpringBoot-0426
* @BelongsPackage: com.anhong
* @Author: anhong
* @CreateTime: 2020-10-24 09:24
* @Description: TODO
*/
@SpringBootApplication
public class APP {
public static void main(String[] args) {