SpringBoot集成调用Quartz定时器
前言
https://blog.youkuaiyun.com/dongdingzhuo/article/details/97110642
在这篇文章的基础上,修改了其配置方式,将quartz.properties中的配置文件替换到yml中,并且不需要QuartzConfig.class
yml中配置
spring:
quartz:
#相关属性配置
properties:
org:
quartz:
scheduler:
instanceName: clusteredScheduler
instanceId: AUTO
jobStore:
class: org.quartz.impl.jdbcjobstore.JobStoreTX
driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate
tablePrefix: QRTZ_
isClustered: true
clusterCheckinInterval: 10000
useProperties: false
threadPool:
class: org.quartz.simpl.SimpleThreadPool
threadCount: 10
threadPriority: 5
threadsInheritContextClassLoaderOfInitializingThread: true
#数据库方式
job-store-type: jdbc
#初始化表结构
#jdbc:
#initialize-schema: never
需要执行的任务
将其需要执行的任务替换为继承QuartzJobBean类,其中写自己需要的业务
import com.jds.core.utils.BaseUtil;
import com.swy.order.service.OrderService;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;
import java.util.HashMap;
import java.util.Map;
public class OrderSettingJob extends QuartzJobBean {
public