解决SpringBoot 2.5.7以上版本Quartz无法启动的问题
将项目中SpringBoot 版本从2.5.6升级到2.5.7后,发现Quartz无法启动了。(DB存储)报错信息如下:
DataSource name not set.
在yaml配置文件中添加DataSource信息后,项目依然报错,但报错信息如下:
Failed to obtain DB connection from data source 'xxxx': java.sql.SQLException: There is no DataSource named 'xxxx'
经过多次尝试之后发现,2.5.7以后,Quartz的配置属性位置发生了变更:
原本的yaml路径为:
Spring:
quartz:
dataSource:
XXXX:
新的yaml路径为:(因为嵌套太多,使用yaml的简洁写法)
Spring:
quartz:
properties.org.quartz:
dataSource:
XXXX:
但手动写入数据源之后依然报错。
经过Gayhub查询issue得知,Spring框架的一项修改引入了这个问题。
附上issue链接: https://github.com/spring-projects/spring-boot/issues/28758
解决办法:
将yaml配置文件中Quartz下jobstore中的class属性注释掉,数据源就可以正常进行自动匹配了。
附上修改后的Quartz配置:
quartz:
defaultJobGroupName: "MEETING_JOB_GROUP"
defaultTriggerGroupName: "MEETING_TRIGGER_GROUP"
jdbc:
initialize-schema: never
job-store-type: jdbc
properties.org.quartz:
scheduler:
instanceName: defaultScheduler
instanceId: AUTO
jobStore:
class: org.quartz.impl.jdbcjobstore.JobStoreTX
driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate
tablePrefix: QRTZ_
isClustered: false
clusterCheckinInterval: 10000
#dataSource: qrtz
threadPool:
class: org.quartz.simpl.SimpleThreadPool
threadCount: 10
threadPriority: 5
threadsInheritContextClassLoaderOfInitializingThread: true
#dataSource.qrtz:
#provider: com.lantian.meeting.config.DruidConnectionPrivider
#driver: org.mariadb.jdbc.Driver
#URL: jdbc:mariadb://localhost:3306/XXXuseUnicode=true&characterEncoding=utf-8&useLegacyDatetimeCode=false&serverTimezone=UTC
#username: xxx
#password: xxx