spring boot - disable quartz scheduler
Asked Answered
E

3

10

I need to be able to set up quartz to run depending on the profile. I am using an integration test to make sure that each profile is getting the scheduler started (or not), but I am checking a profile that doesn't have it enabled and this check is failing:

assertFalse(scheduler.isStarted());

This is what I have used for this profile in application.yaml:

spring:
  quartz:
    enabled: false

Also tried:

spring:
  quartz:
    properties:
      enabled: false

Any ideas how to get quartz to not start at all?

As a workaround, is it possible to set up a dummy scheduler on the profile so that the real quartz is skipped altogether?

PS I have noticed this, but I'd like to keep it in application.yaml if at all possible: How to disable Quartz scheduler for dev and stg environment

Epifaniaepifano answered 29/7, 2020 at 19:46 Comment(1)
For a list of properties, see org.springframework.boot.autoconfigure.quartz.QuartzPropertiesRior
E
11

this worked:

spring:
  quartz:
    auto-startup: false
Epifaniaepifano answered 30/7, 2020 at 16:15 Comment(0)
P
4

In my case, disabling spring.quartz.auto-startup wasn't enough. Quartz was still happily starting and reporting so in the logs:

org.quartz.impl.StdSchedulerFactory      : Using default implementation for ThreadExecutor
org.quartz.core.SchedulerSignalerImpl    : Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl
org.quartz.core.QuartzScheduler          : Quartz Scheduler v.2.3.2 created.
(...)
org.quartz.core.QuartzScheduler          : JobFactory set to: org.springframework.scheduling.quartz.SpringBeanJobFactory@4560eb15

I had to add:

@EnableAutoConfiguration(exclude = { QuartzAutoConfiguration.class })

to the

@SpringBootApplication(...)

...to get rid of it.

Update: Version is Spring Boot v2.7.7, Spring v5.3.24.

Peroxide answered 5/4, 2023 at 11:36 Comment(2)
I also had to exclude the TraceQuartzAutoConfiguration.classEthos
The log output you posted is for quartz initialising, but not actually starting and running jobs.Braille
B
0

Setting spring.quartz.auto-startup=false means that quartz is initialised, but not started (which is what the original poster is after). This means that it will still log messages at application startup, but won't run jobs. Independently of me enabling or disabling auto startup I always get log lines like this:

 org.quartz.core.QuartzScheduler          : Scheduler meta-data: Quartz Scheduler (v2.3.2) 'quartzScheduler' with instanceId 'Aluminium-Apple-2.local1724066382990'
  Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
  NOT STARTED.
  Currently in standby mode.
  Number of jobs executed: 0
  Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads.
  Using job-store 'org.springframework.scheduling.quartz.LocalDataSourceJobStore' - which supports persistence. and is clustered.

but only when I haven't disabled auto startup do I get:

o.s.s.quartz.SchedulerFactoryBean        : Starting Quartz Scheduler now
org.quartz.core.QuartzScheduler          : Scheduler quartzScheduler_$_Aluminium-Apple-2.local1724071911311 started.

near then end of the application startup.

Braille answered 19/8 at 12:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.