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的那个包里面,或者是在那个特定的版本里面?还有,我的配置文件有没有什么问题?麻烦各位大虾看看,指点一下,谢谢~~
...全文
3498 10 打赏 收藏 转发到动态 举报
写回复
用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

81,092

社区成员

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

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