Configuring CronTriggerFactoryBean for quartz clustering with JobStoreTX

匿名 (未验证) 提交于 2019-12-03 00:56:02

问题:

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?

回答1:

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


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!