您的位置:首页 > 编程语言 > Java开发

Spring2.5 定时器 错误 org.springframework.scheduling.quartz.SchedulerFactoryBean#0

2013-12-19 11:55 302 查看
Spring2.5 定时器 错误 记录一下

 

一、 开发环境 MyEclipse6.5 、jdk1.5 、J2EE5

二、 使用技术 struts2 、hibernate、 Spring2.5

(1)、发生问题:严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.scheduling.quartz.SchedulerFactoryBean#0' defined in class path resource [scheduler.xml]: Cannot resolve reference
to bean 'cronTriggerBean' while setting bean property 'triggers' with key [0]; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [org.springframework.scheduling.quartz.CronTriggerBean] for bean with name
'cronTriggerBean' defined in class path resource [scheduler.xml]: problem with class file or dependent class; nested exception is java.lang.IncompatibleClassChangeError: class org.springframework.scheduling.quartz.CronTriggerBean has interface org.quartz.CronTrigger
as super class

 

看到这个错误大概意思,应该是指Spring 在创建这个工厂时发生了错误 class org.springframework.scheduling.quartz.CronTriggerBean
, 好像说是需要继承一个超类,

上网查了一下,spring定时器,有2种配置方法,1是继承超类,2是通过配置。

 

另外,看到其他人工程下比我多一个 quartz-1.5.2.jar,加到工程中,错误解决。



 

 

我是写的xml配置,第1种我没试,所以只介绍第2种,以下是我的配置

1、

<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> 
<!--  在spring文件中引入定时器配置文件 -->
<!-- 定时器 -->
<import resource="classpath:mytimer.xml"/>

</beans>


2、mytimer.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<!-- 定时扫描周期,如果已到期,则结束周期 -->

<!-- 定时服务定义 -->
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<!-- 自动启动 -->
<property name="autoStartup">
<value>true</value>
</property>
<property name="triggers">
<list>
<ref bean="cronTriggerBean" />
</list>
</property>
</bean>

<bean id="cronTriggerBean" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="jobDetailBean" />
</property>
<property name="cronExpression">
<!-- 过一秒开始,每间隔两秒执行-->
<value>1/2 * * * * ?</value>
</property>
</bean>

<bean id="jobDetailBean" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="springTimer"></property>
<property name="targetMethod" value="tiggertimer"></property>
<property name="concurrent" value="false" />
</bean>

<bean id="springTimer" class="cn.com.common.listener.SpringTimer"></bean>
</beans>


3、我的实现类

cn.com.common.listener.SpringTimer

package cn.com.common.listener;

import java.util.Date;

public class SpringTimer {

public void tiggertimer(){

System.out.println(new Date());
}
}


4、启动tomcat ,看到实现类效果



 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  spring concurrent