使用 JobStoreTX 为石英集群配置 CronTriggerFactoryBean [英] Configuring CronTriggerFactoryBean for quartz clustering with JobStoreTX

查看:74
本文介绍了使用 JobStoreTX 为石英集群配置 CronTriggerFactoryBean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用的是 Quartz 2.1.5;我们设置了以下属性:

org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTXorg.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.CloudscapeDelegateorg.quartz.jobStore.useProperties = trueorg.quartz.jobStore.tablePrefix=QRTZ_org.quartz.jobStore.isClustered=trueorg.quartz.jobStore.clusterCheckinInterval=20000

以及以下bean配置:

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

当我们运行时,我们收到一个错误提示

 嵌套异常是 org.quartz.JobPersistenceException:无法为 'sftpTransfers.abcRequestsJob' 存储触发器 'sftpTransfers.abcRequestsJobTrigger'当设置了useProperties"属性时,job:JobDataMap 的值必须是字符串.违规值的关键:jobDetail[请参见嵌套异常:java.io.IOException:当设置了 'useProperties' 属性时,JobDataMap 值必须是字符串.违规值的关键:jobDetail]

除了使用对 JobDetailFactoryBean 引用的引用之外,还有其他方法可以配置 CronTriggerFactoryBean,或者使用仅将字符串作为属性的其他触发器工厂 bean 吗?在我们想要使用集群之前,这一切都有效,但现在作业将被写入 blob,他们只想保留字符串.没关系,我该如何完成?

解决方案

请参考:

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 类 CronTriggerFactoryBeanJobDataMap 中存储了对 JobDetail 的引用,它不能表示为一组属性.

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

解决方法:

扩展 CronTriggerFactoryBean 并从 jobDataMap 中删除 JobDetail.

import org.springframework.scheduling.quartz.CronTriggerFactoryBean;导入 org.springframework.scheduling.quartz.JobDetailAwareTrigger;公共类 PersistableCronTriggerFactoryBean 扩展 CronTriggerFactoryBean {@覆盖公共无效 afterPropertiesSet() {super.afterPropertiesSet();//删除JobDetail元素getJobDataMap().remove(JobDetailAwareTrigger.JOB_DETAIL_KEY);}}

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?

解决方案

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);
    }
}

这篇关于使用 JobStoreTX 为石英集群配置 CronTriggerFactoryBean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆