Restart Quartz jobs stored in DB: how?

Issue with Scheduler Application Using Spring Boot & Quartz

I have a scheduler application which runs using Spring Boot & Quartz. I have created the job with multiple triggers (cron) which is running perfectly fine but the triggers are not firing when the application is restarted. I have tried storing the details of job and triggers at a user-defined table and loading the details upfront when the application starts, but I am not sure if this is the right approach.

I have searched through a lot of articles and github projects to find out how to restart/resume/re-initiate jobs but I haven’t been able to find a solution. I am hoping someone with a better understanding of Quartz can provide an answer.

One possible solution is to use the JobStoreTX as your Quartz job store. This will allow your job and trigger details to be stored in a database, which will persist even after the application is restarted. To configure the JobStoreTX, you can add the following properties to your application.properties file:

spring.quartz.job-store-type=jdbc
spring.quartz.jdbc.initialize-schema=always
spring.quartz.jdbc.url=<your database url>
spring.quartz.jdbc.user=<your database username>
spring.quartz.jdbc.password=<your database password>

You will also need to configure the JobDetail and Trigger beans to use the JobStoreTX:

@Configuration
public class QuartzConfig {

    @Autowired
    private DataSource dataSource;

    @Bean
    public JobDetail jobDetail() {
        return JobBuilder.newJob().ofType(MyJob.class)
            .storeDurably()
            .withIdentity("myJob")
            .withDescription("My Quartz Job")
            .build();
    }

    @Bean
    public Trigger trigger(JobDetail job) {
        return TriggerBuilder.newTrigger().forJob(job)
            .withIdentity("myTrigger")
            .withSchedule(CronScheduleBuilder.cronSchedule("0 * * * * ?"))
            .build();
    }

    @Bean
    public SchedulerFactoryBean schedulerFactoryBean() {
        SchedulerFactoryBean schedulerFactory = new SchedulerFactoryBean();
        schedulerFactory.setDataSource(dataSource);
        schedulerFactory.setJobDetails(jobDetail());
        schedulerFactory.setTriggers(trigger(jobDetail()));
        return schedulerFactory;
    }
}

With this configuration, your job and trigger details should be persisted in the database and should resume running when the application is restarted.