Ensure QuartzDatabaseInitializer is initialized before Scheduler

If the auto-configured `Scheduler` instance backed by JDBC job store is
used as a dependency in an application component, the initialization of
`Scheduler` will be triggered before `QuartzDatabaseInitializer`. This
will result in failure due to schema not being prepared in time for
`Scheduler` to populate job details.

This commit ensures `QuartzDatabaseInitializer` is initialized before the
auto-configured `Scheduler` by introducing a dependency between the two.

See gh-9411
This commit is contained in:
Vedran Pavic
2017-06-05 19:28:28 +02:00
committed by Stephane Nicoll
parent b16fdafa3c
commit db060c847d
6 changed files with 119 additions and 27 deletions

View File

@@ -18,26 +18,40 @@ package sample.quartz;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class SampleQuartzApplication {
public class SampleQuartzApplication implements CommandLineRunner {
@Autowired
private Scheduler scheduler;
public static void main(String[] args) {
SpringApplication.run(SampleQuartzApplication.class, args);
}
@Override
public void run(String... args) throws Exception {
Trigger trigger = TriggerBuilder.newTrigger().forJob(sampleJobDetail())
.withIdentity("startTrigger").usingJobData("name", "Boot").startNow()
.build();
this.scheduler.scheduleJob(trigger);
}
@Bean
public JobDetail sampleJobDetail() {
return JobBuilder.newJob().ofType(SampleJob.class).withIdentity("sampleJob")
.usingJobData("name", "World")
.storeDurably().build();
return JobBuilder.newJob(SampleJob.class).withIdentity("sampleJob")
.usingJobData("name", "World").storeDurably().build();
}
@Bean