在使用Spring3.0和Quartz2.0結合的時候出現的異常

異常信息: java

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
spring

配置文件: spa

<?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>  .net

解決辦法: xml

將doTime標籤中的bean的class由:org.springframework.scheduling.quartz.CronTriggerBean 對象

改成:  org.springframework.scheduling.quartz.CronTriggerFactoryBean便可 blog

具體緣由參見如下連接(本人解決辦法也參照的如此連接知識版權屬於原做者):http://blog.csdn.net/shootyou/article/details/8175754 get

相關文章
相關標籤/搜索