在ssh框架中配置quartz定时器出现:
- 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即可
在这贴出我quartz.xml的配置文件,供大家参考:
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:mvc="http://www.springframework.org/schema/mvc"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns:mybatis="http://mybatis.org/schema/mybatis-spring"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
- http://www.springframework.org/schema/mvc
- http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
- http://mybatis.org/schema/mybatis-spring
- http://mybatis.org/schema/mybatis-spring.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context-3.2.xsd
- http://www.springframework.org/schema/aop
- http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx-3.2.xsd ">
- <bean id="quartzJob" class="com.ahxh.quartz.QuartzJob"></bean>
- <!-- 使用MethodInvokingJobDetailFactoryBean,任务类可以不实现Job借口,通过targetMethod指定调用方法 -->
- <bean id="JobTask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
- <!-- 要调度的对象 -->
- <property name="targetObject" ref="quartzJob" />
- <!-- 要执行的方法名称 -->
- <property name="targetMethod" value="excutor" />
- <!-- 将并发设置为false -->
- <property name="concurrent" value="false"></property>
- </bean>
- <!-- 调度触发器 -->
- <bean id="trigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
- <property name="jobDetail" ref="JobTask" />
- <!-- 表达式 -->
- <property name="cronExpression" value="${qzExcutTimer}" />
- </bean>
- <!-- 调度工厂:如果将lazy-init="false",那么容器启动就会执行调度程序 -->
- <bean id="startQuartz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
- <property name="triggers">
- <list>
- <!-- 作业调度器,list下可加入其它的调度器 -->
- <ref bean="trigger" />
- </list>
- </property>
- </bean>
- </beans>
原文地址:https://www.cnblogs.com/qianzf/p/12354412.html
时间: 2024-11-22 21:18:13