Caused by: java.lang.ClassNotFoundException: org.springframework.scheduling.quartz.CronTriggerBean

在ssh框架中配置quartz定时器出现:

  1. Caused by: java.lang.ClassNotFoundException: org.springframework.scheduling.quartz.CronTriggerBean
  2.     at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
  3.     at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
  4.     at java.security.AccessController.doPrivileged(Native Method)
  5.     at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
  6.     at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
  7.     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
  8.     at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
  9.     at org.springframework.util.ClassUtils.forName(ClassUtils.java:250)
  10.     at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:401)
  11.     at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1432)
  12.     at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1377)
  13.     ... 25 more

实际上是因为quartz的配置信息用的是旧版本、而依赖的确是高版本的jar包

在quartz 1.8.6及以前版本的时候 调度触发器 依赖的类是 org.springframework.scheduling.quartz.CronTriggerBean

在2.xx版本之后就改为了org.springframework.scheduling.quartz.CronTriggerFactoryBean

因此当你依赖2.x.x版本之后只需将调度触发器的依赖类改为 org.springframework.scheduling.quartz.CronTriggerFactoryBean即可

在这贴出我quartz.xml的配置文件,供大家参考:

 

    1. <beans xmlns="http://www.springframework.org/schema/beans"
    2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    3. xmlns:mvc="http://www.springframework.org/schema/mvc"
    4. xmlns:context="http://www.springframework.org/schema/context"
    5. xmlns:aop="http://www.springframework.org/schema/aop"
    6. xmlns:tx="http://www.springframework.org/schema/tx"
    7. xmlns:mybatis="http://mybatis.org/schema/mybatis-spring"
    8. xsi:schemaLocation="http://www.springframework.org/schema/beans
    9. http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
    10. http://www.springframework.org/schema/mvc
    11. http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
    12. http://mybatis.org/schema/mybatis-spring
    13. http://mybatis.org/schema/mybatis-spring.xsd
    14. http://www.springframework.org/schema/context
    15. http://www.springframework.org/schema/context/spring-context-3.2.xsd
    16. http://www.springframework.org/schema/aop
    17. http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
    18. http://www.springframework.org/schema/tx
    19. http://www.springframework.org/schema/tx/spring-tx-3.2.xsd ">
    20.  
    21. <bean id="quartzJob" class="com.ahxh.quartz.QuartzJob"></bean>
    22.  
    23. <!-- 使用MethodInvokingJobDetailFactoryBean,任务类可以不实现Job借口,通过targetMethod指定调用方法 -->
    24. <bean id="JobTask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
    25. <!-- 要调度的对象 -->
    26. <property name="targetObject" ref="quartzJob" />
    27. <!-- 要执行的方法名称 -->
    28. <property name="targetMethod" value="excutor" />
    29. <!-- 将并发设置为false -->
    30. <property name="concurrent" value="false"></property>
    31. </bean>
    32. <!-- 调度触发器 -->
    33. <bean id="trigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
    34. <property name="jobDetail" ref="JobTask" />
    35. <!-- 表达式 -->
    36. <property name="cronExpression" value="${qzExcutTimer}" />
    37. </bean>
    38. <!-- 调度工厂:如果将lazy-init="false",那么容器启动就会执行调度程序 -->
    39. <bean id="startQuartz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    40. <property name="triggers">
    41. <list>
    42. <!-- 作业调度器,list下可加入其它的调度器 -->
    43. <ref bean="trigger" />
    44. </list>
    45. </property>
    46. </bean>
    47.  
    48. </beans>