Can I turn off quartz scheduler with a property setting? Can I turn off quartz scheduler with a property setting? spring spring

Can I turn off quartz scheduler with a property setting?


If you use Spring Framework you can make subclass from org.springframework.scheduling.quartz.SchedulerFactoryBean and override afterPropertiesSet() method.

public class MySchedulerFactoryBean extends org.springframework.scheduling.quartz.SchedulerFactoryBean {    @Autowired    private @Value("${enable.quartz.tasks}") boolean enableQuartzTasks;    @Override    public void afterPropertiesSet() throws Exception {        if (enableQuartzTasks) {            super.afterPropertiesSet();        }     }}

Then change declaration of factory in xml file and set "enable.quartz.tasks" property in properties file. That's all.

Of course, instead using @Autowired you can write and use setter method and add

<property name="enableQuartzTasks" value="${enable.quartz.tasks}"/>

to MySchedulerFactoryBean declaration in xml.


No. But the properties file doesn't start the scheduler.

The scheduler doesn't start until/unless some code invokes scheduler.start().


Seems there is property autoStartup in org.springframework.scheduling.quartz.SchedulerFactoryBean so you can configure it in xml config like this:

<bean id="quartzFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="autoStartup" value="${cron.enabled}"/> <property name="triggers"> <list> <ref bean="someTriggerName"/> </list> </property></bean>

Thanks to https://chrisrng.svbtle.com/configure-spring-to-turn-quartz-scheduler-onoff