4

我们使用的是 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,他们只希望保留字符串。很好,我该怎么做呢?

4

1 回答 1

4

请参考:

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

问题:

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

错误是因为 Spring 类CronTriggerFactoryBean在 中存储了对 的引用,该引用JobDetail不能JobDataMap表示为一组属性。

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

解决方法:

扩展和CronTriggerFactoryBean删除JobDetailjobDataMap

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);
    }
}
于 2013-07-10T10:13:03.113 回答