spring-boot-starter-quartz jdbc vs memory jobstore 不同环境

spring-boot-starter-quartz jdbc vs memory jobstore in different environement

我在几个环境项目中使用 spring-boot-starter-quartz。

在本地环境中,我想使用 memory jobstore(spring.quartz.job-store-type=memory) 在所有其他环境中(preprod,prod ...)我想使用 jdbc jobstore (spring.quartz.job-store-type=jdbc)

我想在默认 application.properties 文件中放入所有常用属性,并仅覆盖本地环境属性文件 (application-local.properties)

中的有用属性

所以通常我会把它放在 application.properties

spring.quartz.job-store-type=jdbc
spring.quartz.jdbc.initialize-schema=never
spring.quartz.properties.org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
spring.quartz.properties.org.quartz.jobStore.useProperties=false
spring.quartz.properties.org.quartz.jobStore.tablePrefix=qrtz_
spring.quartz.properties.org.quartz.jobStore.isClustered=false

并且在申请中-local.properties

spring.quartz.jdbc.initialize-schema=always
spring.quartz.job-store-type=MEMORY

Quartz 不喜欢这个配置。我遇到了 java.lang.NoSuchMethodException: No setter for property 'tablePrefix'

这样的异常

一个简单的解决方案是在每个文件中重复所需的属性(我绝对不想要这个解决方案)。

否则我该怎么办?

我的方法不是很好。 我们可以将 jdbc jobstore 与 h2 数据库一起使用。唯一改变的是 driverDelegateClass。对于 h2,我们需要使用 driverDelegateClass spring.quartz.properties.org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.HSQLDBDelegate.

因此此配置将适用于 h2 数据库:

spring.quartz.job-store-type=jdbc
spring.quartz.jdbc.initialize-schema=always
spring.quartz.properties.org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.HSQLDBDelegate
spring.quartz.properties.org.quartz.jobStore.useProperties=false
spring.quartz.properties.org.quartz.jobStore.tablePrefix=qrtz_
spring.quartz.properties.org.quartz.jobStore.isClustered=false