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

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

你可能感兴趣的:(java,spring,bean,quartz,Blog)