Spring+quartz的任务调度问题

bmj 2008-06-30 03:01:32
我在网上找了些quartz的例子来看了,按照上面写的编写好了配置文件,可是好像有点问题,配置文件如下:
<!-- 要调度的对象 -->
<bean id="day_compute" class="cn.edu.aust.business.Day_auto_compute" />
<bean id="month_compute" class="cn.edu.aust.business.Month_auto_compute" />
<bean id="year_compute" class="cn.edu.aust.business.Year_auto_compute" />


<!-- 由JobDetailBean 负责 -->
<bean id="year_compute_entity" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref local="year_compute" />
</property>
<property name="targetMethod">
<value>compute</value>
</property>
</bean>

<bean id="month_compute_entity" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref local="month_compute" />
</property>
<property name="targetMethod">
<value>compute</value>
</property>
</bean>

<bean id="day_compute_entity" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref local="day_compute" />
</property>
<property name="targetMethod">
<value>compute</value>
</property>
</bean>


<!-- 定义触发的时间 -->
<bean id = "day_cron" class = "org.springframework.scheduling.quartz.CronTriggerBean" >
<property name ="jobDetail" >
<ref bean ="day_compute_entity" />
</property >
<property name ="cronExpression" >
<value > 0 0 2 * * ? </value > <!-- 每天早上2点触发 -->
</property >
</bean >

<bean id = "month_cron" class = "org.springframework.scheduling.quartz.CronTriggerBean" >
<property name ="jobDetail" >
<ref bean ="month_compute_entity" />
</property >
<property name ="cronExpression" >
<value > 0 55 23 L * ? </value > <!-- 每个月最后一天的23点55触发 -->
</property >
</bean >

<bean id = "year_cron" class = "org.springframework.scheduling.quartz.CronTriggerBean" >
<property name ="jobDetail" >
<ref bean ="year_compute_entity" />
</property >
<property name ="cronExpression" >
<value > 0 55 23 12 31 ? * </value > <!-- 每年12月31号的23点55分触发 -->
</property >
</bean >

<!-- 管理触发器 -->
<bean autowire="no"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref local="day_cron" />
<ref local="month_cron" />
<ref local="year_cron" />
</list>
</property>
</bean>
可是运行的时候抛出了异常,异常如下:Cannot find class [org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean] for bean with name 'year_compute_entity' defined in ServletContext resource [/WEB-INF/daoContext.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean。我在spring的核心包里找了,好像没找到org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean这个类啊,可是网上所有的教程基本上都是这么写的,我想问的是org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean这个类是在spring的那个包里面,或者是在那个特定的版本里面?还有,我的配置文件有没有什么问题?麻烦各位大虾看看,指点一下,谢谢~~
...全文
3511 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
sambino 2009-02-25
  • 打赏
  • 举报
回复
我也遇到了同样的问题,由于第一次用Quartz,当时还以为是配置错误,浪费了一晚上时间。
最后想到了jar包问题,我用的是spring2.0以前的版本,在网上找了个spring.jar这个包,导进去后能找到
org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean
org.springframework.scheduling.quartz.CronTriggerBean
org.springframework.scheduling.quartz.SchedulerFactoryBean
这三个类,显示也就正常了。

我的博客中有详细例子演示http://blog.csdn.net/sambino/archive/2009/02/25/3934670.aspx
bmj 2008-07-04
  • 打赏
  • 举报
回复
回楼上的,我使用的是2.5版本的,由于使用了myeclipse做开发,在myelipse自带的spring包里面好像没有spring-context-support.jar这个包。
Landor2004 2008-06-30
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 bmj 的回复:]
问题已经自行解决,quartz这个包在spring-context-support.jar这个jar包里面,不是在spring-context包里面,将spring-context-support.jar加入路径以后可以顺利启动
[/Quote]


你说的这个的spring应该是2.5版本,2.0以前的都是和spring.jar在一起的
bmj 2008-06-30
  • 打赏
  • 举报
回复
问题已经自行解决,quartz这个包在spring-context-support.jar这个jar包里面,不是在spring-context包里面,将spring-context-support.jar加入路径以后可以顺利启动
tianyidan 2008-06-30
  • 打赏
  • 举报
回复
版本问题吧?你的配置应该没什么问题。
bmj 2008-06-30
  • 打赏
  • 举报
回复
配置文件我看了,好像没什么问题。现在的问题是没有org.springframework.scheduling.quartz这个包,这里不能贴图,要能贴图的话我就把那个与scheduling相关的包的图给抓下来了。与scheduling相关的包有5个,分别是org.springframework.scheduling,org.springframework.scheduling.backportconcurrent,org.springframework.scheduling.concurrent,org.springframework.scheduling.support,org.springframework.scheduling.timer。就这5个,然后没有了,我使用的版本是2.5的,不知道是什么问题?
老紫竹 2008-06-30
  • 打赏
  • 举报
回复
还有,你的Tomcat使用的Spring的版本哦!也许那面是一个老版本的,或者有2个版本也说不一定。
清理一下!
老紫竹 2008-06-30
  • 打赏
  • 举报
回复
你确认你的Spring.jar 在
tomncat/shared/lib 目录下面吗???
老紫竹 2008-06-30
  • 打赏
  • 举报
回复
给你一个我的配置,你自己看看吧!
http://www.java2000.net/viewthread.jsp?tid=1643
第1章:对Spring框架进行宏观性的概述,力图使读者建立起对Spring整体性的认识。   第2章:通过一个简单的例子展现开发Spring Web应用的整体过程,通过这个实例,读者可以快速跨入Spring Web应用的世界。   第3章:讲解Spring IoC容器的知识,通过具体的实例详细地讲解IoC概念。同时,对Spring框架的三个最重要的框架级接口进行了剖析,并对Bean的生命周期进行讲解。   第4章:讲解如何在Spring配置文件中使用Spring 3.0的Schema格式配置Bean的内容,并对各个配置项的意义进行了深入的说明。   第5章:对Spring容器进行解构,从内部探究Spring容器的体系结构和运行流程。此外,我们还将对Spring容器一些高级主题进行深入的阐述。   第6章:我们从Spring AOP的底层实现技术入手,一步步深入到Spring AOP的内核中,分析它的底层结构和具体实现。   第7章:对如何使用基于AspectJ配置AOP的知识进行了深入的分析,这包括使用XML Schema配置文件、使用注解进行配置等内容。   第8章:介绍了Spring所提供的DAO封装层,这包括Spring DAO的异常体系、数据访问模板等内容。   第9章:介绍了Spring事务管理的工作机制,通过XML、注解等方式进行事务管理配置,同时还讲解了JTA事务配置知识。   第10章:对实际应用中Spring事务管理各种疑难问题进行透彻的剖析,让读者对Spring事务管理不再有云遮雾罩的感觉。   第11章:讲解了如何使用Spring JDBC进行数据访问操作,我们还重点讲述了LOB字段处理、主键产生和获取等难点知识。   第12章:讲解了如何在Spring中集成Hibernate、myBatis等数据访问框架,同时,读者还将学习到ORM框架的混用和DAO层设计的知识。   第13章:本章重点对在Spring中如何使用Quartz进行任务调度进行了讲解,同时还涉及了使用JDK Timer和JDK 5.0执行器的知识。   第14章:介绍Spring 3.0新增的OXM模块,同时对XML技术进行了整体的了解。   第15章:对Spring MVC框架进行详细介绍,对REST风格编程方式进行重点讲解,同时还对Spring 3.0的校验和格式化框架如果和Spring MVC整合进行讲解。   第16章:有别于一般书籍的单元测试内容,本书以当前最具实战的JUnit4+Unitils+ Mockito复合测试框架对如何测试数据库、Web的应用进行了深入的讲解。   第17章:以一个实际的项目为蓝本,带领读者从项目需求分析、项目设计、代码开发、单元测试直到应用部署经历整个实际项目的整体开发过程。

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧