ClassNotFoundException: org.springframework.scheduling.quartz.CronTriggerBean

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zml_2015/article/details/55004041

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



阅读更多

ClassNotFoundException:

01-13

问题描述:rn昨天下午开始复习javaweb时候 准备重温一遍LoginServlet 遇到了一个之前没遇到的问题rn点击登陆按钮后 提示错误500rnrnMyeclipse 错误信息如下:rnrn严重: Allocate exception for servlet Loginrnjava.lang.ClassNotFoundException: com.servlet.Loginrn at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1285)rn at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)rn at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:520)rn at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:501)rn at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118)rn at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1050)rn at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:779)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:133)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)rn at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)rn at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)rn at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783)rn at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)rn at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:789)rn at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1437)rn at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)rn at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)rn at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)rn at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)rn at java.lang.Thread.run(Thread.java:745)rn rnrn 问题已经解决 根源是class没有立刻生成 XML文件配置正确 但是class在servlet创建后没有生成rn 解决方法 在Myeclipse 界面的 projecet 选项里面的 Build Automatically 打上对勾即可rn rn

ClassNotFoundException

07-20

就是我通过JUnit测试代码是没有任何问题的,但是当请求到达之后就报classNotFound,rn贴代码,结和代码说明:rnrn ApplicationContext ac;rn UserService us;rn @Beforern public void init() rn ac=new ClassPathXmlApplicationContext("spring/spring-mvc.xml","spring/spring-mybatis.xml");rn us=ac.getBean("userService",UserService.class);rn rn @Testrn public void testLogin() rn User user=us.login("18888888888", "1234");rn System.out.println(user);rn rn rn这样一个JUnit的方法测试是可以得到User对象的,先说明我这里采用的是ssm框架,rn但是如下:rnrn @Resourcern private UserService us;rn @ResponseBodyrn @RequestMapping("/login.shop")rn /**rn * 登录,成功是败都返回数据rn * @param username 可以是邮箱,昵称,手机号rn * @param password 登录密码rn * @returnrn */rn public JSONResult login(String username,String password) rn User user=null;rn try rn user=us.login(username, password);rn catch(UserNameException e) rn return new JSONResult("001",e);rn catch(PasswordException e) rn return new JSONResult("002",e);rn rn return new JSONResult(user);rn rn rn rn rn这里执行的时候那个login方法会抛出异常,已验证us,username,password是有被赋值的。异常信息如下:rnrn 严重: Servlet.service() for servlet [shop] in context with path [/MobileShop] threw exception [Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'oracle.jdbc.OracleDriver'] with root causern java.lang.ClassNotFoundException: oracle.jdbc.OracleDriverrn at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1333)rn at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1167)rn at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1420)rn at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)rn at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)rn at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:203)rn at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:372)rn at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:417)rn at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:255)rn at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)rn at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)rn at com.sun.proxy.$Proxy18.registByTel(Unknown Source)rn at com.chanct.shop.personal.controller.Regist.registByTel(Regist.java:52)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)rn at java.lang.reflect.Method.invoke(Unknown Source)rn at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)rn at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)rn at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)rn at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)rn at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)rn at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)rn at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)rn at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)rn at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:953)rn at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:855)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)rn at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:829)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)rn at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)rn at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)rn at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)rn at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1132)rn at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)rn at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1533)rn at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1489)rn rn感觉我都是用的同一个方法,但是关系导spring就报错了,测试就蛮好rn搞了半天了,实在弄不懂是哪里错了,跪求指点rnrn大家都说驱动。。。。附图rn![图片说明](https://img-ask.csdn.net/upload/201707/20/1500544254_983255.png)![图片说明](https://img-ask.csdn.net/upload/201707/20/1500544315_581941.png)rnrn求能真正解决问题的

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