Springboot整合Quartz数据库方式
...小于 1 分钟
Springboot整合Quartz数据库方式
引入依赖
quartz:
#相关属性配置
properties:
org:
quartz:
scheduler:
instanceName: clusteredScheduler
instanceId: AUTO
jobStore:
class: org.quartz.jobStore.class=org.springframework.scheduling.quartz.LocalDataSourceJobStore
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
解决报错
org.quartz.SchedulerConfigException: DataSource name not set.
原因分析: spring-boot-starter-quartz 2.5.6 之前使用org.quartz.impl.jdbcjobstore.JobStoreTX定义quartz的默认数据源支持,即如下配置:
org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX
解决方案:升级 spring-boot-starter-quartz > 2.5.6 的版本后将不再支持此方式进行配置默认数据源,需改为如下配置:
org.quartz.jobStore.class=org.springframework.scheduling.quartz.LocalDataSourceJobStore
参考文章: