Andrei Ivanov opened SPR-13649 and commented

Trying to create a clustered Quartz configuration is a bit difficult since the reference documentation doesn't have any info about it and Google returns some pretty old blog posts with old versions of Spring.

What I would like to see improved: - section on creating a clustered scheduler. Something like

<bean id="taskScheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="transactionManager" ref="transactionManager" />
    <property name="taskExecutor" ref="taskExecutor" />
    <property name="overwriteExistingJobs" value="true" />
    <property name="quartzProperties">
        <props>
            <prop key="org.quartz.scheduler.instanceId">AUTO</prop>
            <prop key="org.quartz.jobStore.tablePrefix">qrtz_</prop>
            <prop key="org.quartz.jobStore.isClustered">true</prop>
            <prop key="org.quartz.jobStore.useProperties">true</prop>
        </props>
    </property>
</bean>
  • A note regarding MethodInvokingJobDetailFactoryBean that it can't be used for clustered Quartz (or even better, improve it to work)
  • A sample of a jobDetail with DI, I assume with SpringBeanJobFactory The way I've done this is by using @Configurable, as would make DI work on deserialization too (I've used the same approach on JSF beans)
@Configurable
public class UsersSyncJob extends QuartzJobBean implements Serializable {
    @Autowired
    private transient UserFacade userFacade;

    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
        userFacade.syncUsers();
    }
}
  • Sample usage of SchedulerAccessorBean for when you want to register jobs/triggers from separate modules (I've discovered this nice utility by looking at the source code):
<bean class="org.springframework.scheduling.quartz.SchedulerAccessorBean">
    <property name="scheduler" ref="taskScheduler" />
    <property name="triggers">
        <list>
            <ref bean="usersSyncJobTrigger" />
        </list>
    </property>
</bean>

1 votes, 2 watchers