解决Spring中使用quartz发生NotSerializableException methodInvoker的问题

解决Spring中使用quartz发生NotSerializableException methodInvoker的问题Spring2.5+quartz1.6.5发生如下异常 Causedby:org.quartz.JobPersistenceException:Couldn’tstorejob:UnabletoserializeJobDataMapforinsertionintodatabasebecausethevalueofproperty’methodIn…

大家好,欢迎来到IT知识分享网。解决Spring中使用quartz发生NotSerializableException

Spring2.5 + quartz1.6.5 发生如下异常

 

Caused by: org.quartz.JobPersistenceException: Couldn’t store job: Unable to serialize JobDataMap for insertion into database because the value of property ‘methodInvoker’ is not serializable: org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean [See nested exception: java.io.NotSerializableException: Unable to serialize JobDataMap for insertion into database because the value of property ‘methodInvoker’ is not serializable: org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean]
        at org.quartz.impl.jdbcjobstore.JobStoreSupport.storeJob(JobStoreSupport.java:1105)

 

这是Spring的Bug, 解决方法 http://jira.springframework.org/browse/SPR-3797
下载BeanInvokingJobDetailFactoryBean.java 和 MethodInvokingJobDetailFactoryBean.java
在Spring配置文件中使用如下方式

 

<bean id="exampleBean" class="example.ExampleImpl"> 
</bean>

<bean id="exampleTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> 
	<!-- Execute exampleBean.fooBar() at 2am every day -->
	<property name="cronExpression" value="0 0 2 * * ?" />
	<property name="jobDetail"> 
		<bean class="frameworkx.springframework.scheduling.quartz.BeanInvokingJobDetailFactoryBean"> 
			<property name="concurrent" value="false"/>
			<property name="targetBean" value="exampleBean" />
			<property name="targetMethod" value="fooBar" />
			<property name="arguments"> 
				<list> 
					<value>arg1Value</value>
					<value>arg2Value</value> 
				<list> 
			</property> 
		</bean> 
	</property> 
</bean> 

<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> 
	<property name="triggers"> 
		<list> 
			<ref bean="exampleTrigger" /> 
		</list> 
	</property> 
</bean>

 

附件是BeanInvokingJobDetailFactoryBean.java 和 MethodInvokingJobDetailFactoryBean.java

 

参考 http://soulshard.iteye.com/blog/337886

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/21151.html

(0)
上一篇 2024-01-25 10:45
下一篇 2024-01-27 16:00

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注微信