使用Spring配置管理Quartz的時候會遇到下面的異常:java
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中的接口不兼容。spring
解決辦法:CronTriggerBean 替換成 CronTriggerFactoryBean。併發
配置以下:app
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> ide
<property name="triggers"> spa
<list> 線程
<ref bean="billTrigger"/> 接口
</list> get
</property> it
<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"/>