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 庫)時遇到了這個問題,錯誤與這個帖子問題中的錯誤相同。
添加回答
舉報