云淡风轻的博客

寻门而入,破门而出(博客搬家至个人博客:http://wuyongshi.top)

ClassNotFoundException: org.springframework.scheduling.quartz.CronTriggerBean

spring4.3.6与quartz 2.2.3集成出现以下问题

Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.scheduling.quartz.CronTriggerBean] for bean with name 'articleBatchRunTrigger' defined in class path resource [spring-quartz.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.scheduling.quartz.CronTriggerBean
    at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1385)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:641)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:609)
    at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1484)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:425)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:403)
    at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:220)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1260)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1101)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585)
    ... 15 more
Caused by: java.lang.ClassNotFoundException: org.springframework.scheduling.quartz.CronTriggerBean
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at org.springframework.util.ClassUtils.forName(ClassUtils.java:250)
    at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:401)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1432)
    at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1377)
    ... 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即可

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

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
 
    <!--     ****************************************配置跑批**************************************-->
            <!-- 线程执行器配置,用于任务注册 --> 
     <bean id="executor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">  
     <property name="corePoolSize" value="10" />  
     <property name="maxPoolSize" value="100" />  
     <property name="queueCapacity" value="500" />  
    </bean>  
<!--     
    ============= 业务对象=============                         将需要添加定时任务调度的类配置到这里 -->
     <bean id="articleBatchRun" class="top.wys.developerclub.batchprocess.ArticleBatchRun" />
     
     <!-- ============= 调度业务=============  -->
    <bean id="articleBatchRunService" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <!-- 要调用的对象 -->
        <property name="targetObject" ref="articleBatchRun" />
        <!-- 要执行的方法名称 -->
        <property name="targetMethod" value="count" />
        <!-- 如果前一个任务还没有结束第二个任务不会启动 false -->
        <property name="concurrent" value="false" />
    </bean>
     
     
    <!-- ============= 调度触发器 ============= -->
    <bean id="articleBatchRunTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
        <property name="jobDetail" ref="articleBatchRunService" />
                            <!-- 每隔3秒钟审批一次 -->
        <property name="cronExpression" value="0/3 * * * * ?" />
    </bean>
     
    <!-- ============= 调度工厂 =============  -->
    <bean id="schedulerBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" lazy-init="false">
        <property name="triggers">
            <list>
                <!-- add by 郑明亮 2017年2月12日19:58:13 用于定时爬取文章 -->
              <ref bean="articleBatchRunTrigger"/> 
             
            </list>
        </property>
    </bean>
     
 
</beans>

更多关于quartz定时任务调度相关资料,请看这里 

Quartz任务调度框架

文章首次发布于个人博客(吾勇士的博客):http://wuyongshi.top/articles/2017/02/12/1486899247304.html



阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zml_2015/article/details/55004041
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭