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

1 Answers

1
Strelok On

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