WARNING: Unable to load class [org.springframework.scheduling.quartz.JobDetailBean] to check against the @HandlesTypes annotation of one or more ServletContentInitializers. java.lang.IncompatibleClassChangeError: class org.springframework.scheduling.quartz.JobDetailBean has interface org.quartz.JobDetail as super class at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:791) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2820) at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1150) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523) at org.apache.catalina.startup.ContextConfig.checkHandlesTypes(ContextConfig.java:2006) at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:1969) at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:1858) at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1826) at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:1812) at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1306) at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:896) at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:322) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119) at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5103) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:148) at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3854) at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:424) at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1214) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1400) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1410) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1410) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1389) at java.lang.Thread.run(Thread.java:722)
我的配置文件:
<?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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- QUARTZ相关配置 --> <!-- 任务类 --> <bean id="myJob" class="cn.ncss.jym.ChsiValidate.quartz.JobTask" /> <bean id="myJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject" ref="myJob"/> <property name="targetMethod"> <value>startJob</value> </property> </bean> <!-- 触发器 --> <bean id="cronTiggerBean" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> <property name="jobDetail" ref="myJobDetail" /> <property name="cronExpression" value="* 15 * * * ?"/> </bean> <!-- 调度器工厂 --> <bean id="startQuartz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <ref bean="cronTiggerBean"/> </list> </property> </bean> </beans>
今天在公司整合Quartz和spring的时候,出现了以上的问题,找原因找不到,网上有说是版本问题,但是我看了spring3.X版本不能整合Quartz2.x版本的,只能和1.x的搭配使用,而我的是spring4.0.6+Quartz2.2.1,应该不会有不兼容的问题,于是根据错误提示开始看源码,
在org.springframework.scheduling.quartz.JobDetailBean中发下以下注释,
NOTE: This convenience subclass does not work against Quartz 2.0.</b> * Use Quartz 2.0's native {@code JobDetailImpl} class or the new Quartz 2.0 * builder API instead. Alternatively, switch to Spring's {@link JobDetailFactoryBean} * which largely is a drop-in replacement for this class and its properties and * consistently works against Quartz 1.x as well as Quartz 2.x.
我看了一下配置文件,又看了一下 org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean的源码,也确实是用的JobDetailImpl类
public class MethodInvokingJobDetailFactoryBean extends ArgumentConvertingMethodInvoker implements FactoryBean<JobDetail>, BeanNameAware, BeanClassLoaderAware, BeanFactoryAware, InitializingBean { private static Class<?> jobDetailImplClass; private static Method setResultMethod; static { try { jobDetailImplClass = ClassUtils.forName("org.quartz.impl.JobDetailImpl", MethodInvokingJobDetailFactoryBean.class.getClassLoader()); } catch (ClassNotFoundException ex) { jobDetailImplClass = null; } ……
发现如下:
有人说是tomcat版本的问题,我看了一下自己的是tomcat7.0.22的,于是换了tomcat7.0.54的
成功类了~~~~果然是tomcat的版本的问题!!