项目运行发现出现以下错误:
java.lang.IncompatibleClassChangeError: class org.springframework.scheduling.quartz.CronTriggerBean has interface org.quartz.CronTrigger as super class
在网上查阅问题时,有人说是有jar包重复,检查未发现问题。在查阅一看有人说是spring3.1.x和quartz2.x有不兼容问题,查看发现org.springframework.context.support-3.1.1中org.springframework.scheduling.quartz.CronTriggerBean继承了org.quartz.CronTrigger(public class CronTriggerBeanextends CronTrigger),而在quartz2.1.6中org.quartz.CronTrigger是个接口(publicabstract interface CronTrigger extends Trigger),而在quartz1.8.5及1.8.4中org.quartz.CronTrigger是个类(publicclass CronTrigger extends Trigger),从而造成无法在applicationContext中配置触发器。
现在spring3.x为了解决该问题已更新了相应的API,只需将JobDetailBean和SimpleTriggerBean改成JobDetailFactoryBean和SimpleTriggerFactoryBean即可,如果使用cron也是一样,只需改成对应的CronFactoryBean。
<bean id="gdw376KeepingJob" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass" value="com.ao.quartz.job.KeepingJob" />
<property name="jobDataMap">
<map>
<entry key="EnvironmentBuilder" value-ref="gdw376EnvBuilder"></entry>
</map>
</property>
</bean>
<bean id="gdw376KeepingTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean">
<property name="jobDetail" ref="gdw376KeepingJob" />
<property name="repeatInterval" value="${keeping.repeatInterval}" />
</bean>