4 回答

TA贡献1772条经验 获得超5个赞
SpringBoot 有 Quartz 自动配置,你不需要使用 quartz.properties 配置 Quartz,因为它对 Spring 一无所知,所以你不能只把数据源名称放在那里。阅读文档。
开始使用 Quartz 所需要做的就是在 pom.xml 中包含 starter:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-quartz</artifactId> </dependency>
配置您的标准 Spring 数据源(application.properties):
spring.datasource.url = jdbc:postgresql://localhost:5432/quartzspring.datasource.username = admin spring.datasource.password = admin
然后添加(在 application.properties 中):
spring.quartz.job-store-type=jdbc # Add the below line to have Spring Boot auto create the Quartz tables spring.quartz.jdbc.initialize-schema=always
如果你想将额外的属性传递给 Quartz,你可以spring.quartz.properties
像这样在属性名前面加上前缀:
spring.quartz.properties.org.quartz.scheduler.instanceName=LivingOrdering

TA贡献1810条经验 获得超4个赞
从 application.properties 文件中删除 spring.datasource.* 并spring.datasource.name= quartzDataSource
为我添加作品。
你可能还需要配置你
org.quartz.dataSource.quartzDataSource.provider
的(hikaricp 或 c3po-default)

TA贡献1871条经验 获得超13个赞
我知道这个问题很老了,
但由于我最终来到这里寻找解决方案,而且不清楚该怎么做,所以我会为仍在寻找解决方案的其他人提供我的解决方案。
项目配置:
JDK:18.0.1
Maven:3.6.3
Spring boot:2.7.4
Quartz:spring-boot-starter-quartz
如果你想为你的应用程序和 quartz 使用单个数据源,则以下配置有效。
例如,我将它用于测试。
spring:
datasource:
url: jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
driverClassName: org.h2.Driver
username: sa
password: sa
quartz:
job-store-type: jdbc
jdbc:
initialize-schema: never
properties:
org:
quartz:
jobStore:
class: org.springframework.scheduling.quartz.LocalDataSourceJobStore
driverDelegateClass: org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
tablePrefix: TB_PR_QRTZ_
也不要忘记使用@QuartzDatasource 标记您的数据源bean。
@Primary
@Bean
@QuartzDataSource
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource defaultDatasource (){
return DataSourceBuilder.create().build();
}
但是,如果您需要 2 个数据源,则必须在 spring.quartz.properties.org.quartz.dataSource 中指定自定义数据源这是我的应用程序配置
spring:
datasource:
byq:
url: jdbc:oracle:thin:@//app-db/schema-name
driverClassName: oracle.jdbc.OracleDriver
username: ZZZ
password: XXX
quartz:
job-store-type: jdbc
wait-for-jobs-to-complete-on-shutdown: true
jdbc:
initialize-schema: never
properties:
org:
quartz:
dataSource:
quartzDataSource:
URL: jdbc:postgresql://scheduler-db/scheduler
driver: org.postgresql.Driver
user: ZZZ
password: XXX
jobStore:
dataSource: quartzDataSource
class: org.quartz.impl.jdbcjobstore.JobStoreTX
driverDelegateClass: org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
tablePrefix: TB_QRTZ_

TA贡献1828条经验 获得超3个赞
请注意,在quartz.properties
文件中,属性名称以org.quartz...
;开头 对于更高版本的石英(如果我没记错的话,在 2.5.6 之后)它们以spring.quartz.properties.org.quartz...
.
当我将 SpringBoot 版本从 2.1.2 更新到 2.6.3(包括 quartz 库)时遇到了这个问题,错误与这个帖子问题中的错误相同。
添加回答
举报