Spring3.0不支持Quartz2.0,因為org.quartz.CronTrigger在2.0從class變成了一個interface造成IncompatibleClassChangeError錯誤:
Caused by: java.lang.IncompatibleClassChangeError: class org.springframework.scheduling.quartz.CronTriggerBean has interface org.quartz.CronTrigger as super class
今天剛下載了Spring3.2.4,發現這個新版本已經支持quartz2.x了.以前的Spring版本只支持Quartz-1.8.x及以前的版本,做個小實例分享一下.
注:Spring3.2.4配置文件中使用CronTriggerFactoryBean來集成quartz2.x,使用CronTriggerBean來集成quartz1.8.x及以前版本.
Spring-3.2.4 + Quartz-2.2.0集成實例代碼下載地址:
免費下載地址在 http://linux.linuxidc.com/
用戶名與密碼都是www.linuxidc.com
具體下載目錄在 /2013年資料/10月/17日/Spring-3.2.4 + Quartz-2.2.0集成實例
下載方法見 http://www.linuxidc.com/Linux/2013-07/87684.htm
代碼結構及引用jar見下圖:
applicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<!-- 啟動觸發器的配置開始 -->
<bean name="startQuertz" lazy-init="false" autowire="no"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="myJobTrigger" />
</list>
</property>
</bean>
<!-- 啟動觸發器的配置結束 -->
<!-- 調度的配置開始 -->
<!--
quartz-1.8以前的配置
<bean id="myJobTrigger"
class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="myJobDetail" />
</property>
<property name="cronExpression">
<value>0/1 * * * * ?</value>
</property>
</bean>
-->
<!-- quartz-2.x的配置 -->
<bean id="myJobTrigger"
class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail">
<ref bean="myJobDetail" />
</property>
<property name="cronExpression">
<value>0/1 * * * * ?</value>
</property>
</bean>
<!-- 調度的配置結束 -->
<!-- job的配置開始 -->
<bean id="myJobDetail"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref bean="myJob" />
</property>
<property name="targetMethod">
<value>work</value>
</property>
</bean>
<!-- job的配置結束 -->
<!-- 工作的bean -->
<bean id="myJob" class="com.tgb.lk.demo.quartz.MyJob" />
</beans>
更多詳情見請繼續閱讀下一頁的精彩內容: http://www.linuxidc.com/Linux/2013-10/91524p2.htm