使用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"/>