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">
&lt;!-- 	****************************************配置跑批**************************************--&gt;
		&lt;!-- 线程执行器配置,用于任务注册 --&gt;  
 &lt;bean id="executor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"&gt;  
 &lt;property name="corePoolSize" value="10" /&gt;  
 &lt;property name="maxPoolSize" value="100" /&gt;  
 &lt;property name="queueCapacity" value="500" /&gt;  
&lt;/bean&gt;  

<!--
============= 业务对象============= 将需要添加定时任务调度的类配置到这里 -->
<bean id="articleBatchRun" class="top.wys.developerclub.batchprocess.ArticleBatchRun" />

 &lt;!-- ============= 调度业务=============  --&gt;
&lt;bean id="articleBatchRunService" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"&gt;
	&lt;!-- 要调用的对象 --&gt;
	&lt;property name="targetObject" ref="articleBatchRun" /&gt;
	&lt;!-- 要执行的方法名称 --&gt;
	&lt;property name="targetMethod" value="count" /&gt;
	&lt;!-- 如果前一个任务还没有结束第二个任务不会启动 false --&gt;
	&lt;property name="concurrent" value="false" /&gt;
&lt;/bean&gt;


&lt;!-- ============= 调度触发器 ============= --&gt;
&lt;bean id="articleBatchRunTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"&gt;
	&lt;property name="jobDetail" ref="articleBatchRunService" /&gt;
						&lt;!-- 每隔3秒钟审批一次 --&gt;
	&lt;property name="cronExpression" value="0/3 * * * * ?" /&gt;
&lt;/bean&gt;

&lt;!-- ============= 调度工厂 =============  --&gt;
&lt;bean id="schedulerBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" lazy-init="false"&gt;
	&lt;property name="triggers"&gt;
		&lt;list&gt;
			&lt;!-- add by zml2015 2017年2月12日19:58:13 用于定时爬取文章 --&gt;
		  &lt;ref bean="articleBatchRunTrigger"/&gt; 
		
		&lt;/list&gt;
	&lt;/property&gt;
&lt;/bean&gt;

</beans>

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

Quartz任务调度框架

 

 

 

Q.E.D.