arcy
arcy

Reputation: 13123

Configuring CronTriggerFactoryBean for quartz clustering with JobStoreTX

We are using Quartz 2.1.5; we have the following properties set:

org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.CloudscapeDelegate
org.quartz.jobStore.useProperties = true
org.quartz.jobStore.tablePrefix=QRTZ_
org.quartz.jobStore.isClustered=true
org.quartz.jobStore.clusterCheckinInterval=20000

and the following beans configuration:

<bean name="abcRequestsJob" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
    <property name="jobClass" value="com.hsc.correspondence.job.AbcRequestsJob" />
    <property name="group" value="sftpTransfers"/>
</bean>


<bean id="abcRequestsJobTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
    <property name="jobDetail" ref="abcRequestsJob" />
    <property name="group" value="sftpTransfers"/>
    <property name="cronExpression" value="${quartz.abcRequests.cronExpression}" />
</bean>

When we run, we are getting an error saying that

nested exception is org.quartz.JobPersistenceException: Couldn't store trigger 'sftpTransfers.abcRequestsJobTrigger' for 'sftpTransfers.abcRequestsJob' 
job:JobDataMap values must be Strings when the 'useProperties' property is set.  
Key of offending value: jobDetail 
[See nested exception: java.io.IOException: JobDataMap values must be Strings when the 'useProperties' property is set. Key of offending value: jobDetail]

Is there another way to configure a CronTriggerFactoryBean than using a reference to the JobDetailFactoryBean reference, or a different trigger factory bean that only takes strings as properties? This all worked before we wanted to use clustering, but now that the job is going to be written to a blob they want only strings to be persisted. That's fine, how do I get it done?

Upvotes: 4

Views: 10640

Answers (1)

charybr
charybr

Reputation: 1948

Please refer:

http://site.trimplement.com/using-spring-and-quartz-with-jobstore-properties/ http://forum.springsource.org/archive/index.php/t-130984.html

Problem:

This happens with Spring Framework and Quartz together when using org.quartz.jobStore.useProperties=true, meaning that all Job data is stored in the database as properties instead of serialized Java objects.

Error is because of Spring class CronTriggerFactoryBean that stores a reference to the JobDetail in the JobDataMap, which cannot be represented as a set of properties.

CronTriggerFactoryBean is setting the jobDetail into the trigger's jobDataMap.

Workaround:

Extend CronTriggerFactoryBean and remove JobDetail from jobDataMap.

import org.springframework.scheduling.quartz.CronTriggerFactoryBean;
import org.springframework.scheduling.quartz.JobDetailAwareTrigger;

public class PersistableCronTriggerFactoryBean extends CronTriggerFactoryBean {

    @Override
    public void afterPropertiesSet() {
        super.afterPropertiesSet();

        //Remove the JobDetail element
        getJobDataMap().remove(JobDetailAwareTrigger.JOB_DETAIL_KEY);
    }
}

Upvotes: 5

Related Questions