使用JobStoreTX为石英聚类配置CronTriggerFactoryBean

时间:2013-06-17 15:13:38

标签: java spring quartz-scheduler

我们正在使用Quartz 2.1.5;我们设置了以下属性:

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

以及以下bean配置:

<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>

当我们跑步时,我们收到错误说

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]

是否有另一种配置CronTriggerFactoryBean的方法,而不是使用对JobDetailFactoryBean引用的引用,或者只使用字符串作为属性的其他触发器工厂bean?这一切在我们想要使用群集之前都有效,但是现在要将作业写入blob,他们只希望持久化字符串。那没关系,我怎么做呢?

1 个答案:

答案 0 :(得分:5)

请参阅:

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

问题:

使用org.quartz.jobStore.useProperties=true时,Spring Framework和Quartz会一起发生这种情况,这意味着所有作业数据都作为属性而不是序列化的Java对象存储在数据库中。

错误是因为Spring类CronTriggerFactoryBean存储了JobDetailJobDataMap的引用,该引用无法表示为一组属性。

CronTriggerFactoryBean正在将jobDetail设置为触发器的jobDataMap

解决方法:

扩展CronTriggerFactoryBean并从JobDetail移除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);
    }
}