在使用Spring3.0和Quartz2.0结合的时候出现的异常

异常信息:

Exception in thread “main” org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [org.springframework.scheduling.quartz.CronTriggerBean] for bean with name ‘doTime’ defined in class path resource [quartz-config.xml]: problem with class file or dependent class; nested exception is java.lang.IncompatibleClassChangeError: class org.springframework.scheduling.quartz.CronTriggerBean has interface org.quartz.CronTrigger as super class
 at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1269)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:581)
 at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1335)
 at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:901)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:607)
 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
 at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
 at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
 at com.wafer.springquartz.Test.main(Test.java:10)
Caused by: java.lang.IncompatibleClassChangeError: class org.springframework.scheduling.quartz.CronTriggerBean has interface org.quartz.CronTrigger as super class
 at java.lang.ClassLoader.defineClass1(Native Method)
 at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
 at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
 at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
 at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
 at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
 at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
 at org.springframework.util.ClassUtils.forName(ClassUtils.java:260)
 at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:416)
 at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1287)
 at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1258)
 … 9 more

配置文件:

<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE beans PUBLIC “-//SPRING//DTD BEAN//EN” “http://www.springframework.org/dtd/spring-beans.dtd“>
<beans>     
 <!–一: 调用工作的类 –>
 <bean id=”myjob” class=”com.wafer.springquartz.MyJob”>
 </bean>
 
 <!–二: 定义调用对象和调用对象的方法 –>
 <bean id=”jobinfo” class=”org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean”>
  <!– 1.调用的类 –>
  <property name=”targetObject”>
   <ref bean=”myjob”/>
  </property>
  <!– 2.调用的方法 –>
  <property name=”targetMethod”>
   <value>helloword</value>
  </property>
 </bean>
 
 <!–三:定义触发时间   org.springframework.scheduling.quartz.CronTriggerFactoryBean–>
 <bean id=”doTime” class=”org.springframework.scheduling.quartz.CronTriggerBean”>
  <property name=”jobDetail”>
   <ref bean=”jobinfo”/>
  </property>
  <!–con表达式 –>
  <property name=”cronExpression”>
   <value>10,15,20,25,30,35,40,45,50,55 * * * * ?</value>
  </property>
 </bean>
 
  <!–四:总管理类 如果将lazy-init=’false’那么容器启动就会执行调度程序 –>
 <bean id=”StartQuertz” lazy-init=”false” autowire=”no” class=”org.springframework.scheduling.quartz.SchedulerFactoryBean”>
  <property name=”triggers”>
   <list>
    <ref bean=”doTime”/>
   </list>
  </property>
 </bean>
</beans> 

解决办法:

将doTime标签中的bean的class由:org.springframework.scheduling.quartz.CronTriggerBean

改为:  org.springframework.scheduling.quartz.CronTriggerFactoryBean即可

具体原因参见以下链接(本人解决办法也参照的如此链接知识版权属于原作者):http://blog.csdn.net/shootyou/article/details/8175754

 

 

Caused by: java.lang.IncompatibleClassChangeError: class org.springframework.scheduling.quartz.CronTriggerBean has interface org.quartz.CronTrigger as super class

 

原因是Spring 3.0版本中内置的Quartz版本是<2.0的,在使用最新的Quartz包(>2.0)之后,接口不兼容。

 

解决办法有两种:

1.降低Quartz版本,降到1.X去。

 

2.升级Spring版本到3.1+,根据Spring的建议,将原来的**TriggerBean替换成**TriggerFactoryBean,例如CronTriggerBean 就可以替换成 CronTriggerFactoryBean。替换之后问题解决。

你可能感兴趣的:(Spring3)