使用Spring配置管理Quartz的時候會遇到下面的異常:
Caused by: java.lang.IncompatibleClassChangeError: class org.springframework.scheduling.quartz.CronTriggerBean has interface org.quartz.CronTrigger as super class
原因是Spring 3.2版本中內置的Quartz版本與Quartz包2.2中的接口不兼容。
解決辦法:CronTriggerBean 替換成 CronTriggerFactoryBean。
配置如下:
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="billTrigger"/>
</list>
</property>
<property name="autoStartup" value="true"/>
</bean>
<bean id="billTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="billJobDetail"/>
<property name="cronExpression" value="59/1 * * * * ?"/>
</bean>
<!-- 每隔1秒鐘觸發一次 -->
<bean id="billJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="billJob"/>
<property name="targetMethod" value="execute"/>
<property name="concurrent" value="false"/>
</bean> <!-- 是否允許任務併發執行。當值爲false時,表示必須等到前一個線程處理完畢後纔再啓一個新的線程 -->
<bean id="billJob" class="cn.com.infinitus.moa.application.job.DownloadBillJob"/>