Reputation: 61
This is my config file quartz.properties
org.quartz.scheduler.instanceName= LivingOrdering
org.quartz.scheduler.instanceId=99199
org.quartz.scheduler.rmi.export=false
org.quartz.scheduler.rmi.proxy=false
org.quartz.threadPool.class=org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount=3
org.quartz.context.key.QuartzTopic=QuartzPorperties
org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.tablePrefix=qrtz_
org.quartz.jobStore.dataSource=quartzDataSource
org.quartz.dataSource.quartzDataSource.driver=org.postgresql.Driver
org.quartz.dataSource.quartzDataSource.URL=jdbc:postgresql://localhost:5432/quartz
org.quartz.dataSource.quartzDataSource.user=admin
org.quartz.dataSource.quartzDataSource.password=admin
org.quartz.dataSource.quartzDataSource.maxConnections=300
I am getting error at the line -:
Scheduler scheduler = new StdSchedulerFactory().getScheduler();
Error: org.quartz.SchedulerException: Could not initialize DataSource: quartzDataSource
Upvotes: 4
Views: 21326
Reputation: 432
I know the question is old, but since I ended up here looking for a solution, and that it wasn't clear what to do, I will provide my solution for the others still looking for one.
Project config:
JDK: 18.0.1
Maven: 3.6.3
Spring boot: 2.7.4
Quartz: spring-boot-starter-quartz
The below config works if you want to have a single datasource for your app and quartz.
I use it for tests for example.
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_
Also don't forget to tag your datasource bean with @QuartzDatasource
.
@Primary
@Bean
@QuartzDataSource
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource defaultDatasource (){
return DataSourceBuilder.create().build();
}
But if you need 2 datasources, you have to specify a custom datasource in spring.quartz.properties.org.quartz.dataSource.
Here is my config for the app:
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_
Upvotes: 4
Reputation: 183
get rid of spring.datasource.* from application.properties file and , add spring.datasource.name= quartzDataSource
works for me.
org.quartz.dataSource.quartzDataSource.provider
as well (hikaricp or c3po-default)Upvotes: -1
Reputation: 71
As a note here, in the quartz.properties
file, the properties names start with org.quartz...
; with the later versions of quartz (after 2.5.6 if I'm not wrong) they start with spring.quartz.properties.org.quartz...
.
Just had this issue when I've updated the SpringBoot version from 2.1.2 to 2.6.3 (including quartz libraries) and the error was the same as in this post question.
Upvotes: 0
Reputation: 51481
SpringBoot has Quartz auto configuration, you don't need to configure Quartz using quartz.properties as it knows nothing about Spring so you cannot just put a datasource name in there. Read the documentation.
All you need to get started with Quartz is to include the starter in you pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-quartz</artifactId>
</dependency>
Configure your standard Spring datasource (application.properties):
spring.datasource.url = jdbc:postgresql://localhost:5432/quartz
spring.datasource.username = admin
spring.datasource.password = admin
Then add (in 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
If you want to pass additional properties to Quartz you can prefix the property name with spring.quartz.properties
like so:
spring.quartz.properties.org.quartz.scheduler.instanceName=LivingOrdering
Upvotes: 2