2006-12-18
Spring配置Quartz例子
关键字: spring quartz<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <!--起动Bean--> <bean id="z" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <ref bean="cronReportTrigger"/> </list> </property> </bean> <!--实际的工作Bean--> <bean id="courseService" class="com.spring.helloworld.CourseService"></bean> <!--jobBean用于设定启动时运用的Bean与方法--> <bean id="scheduledReportJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject"> <ref bean="courseService"/> </property> <property name="targetMethod"> <value>sendCourseEnrollmentReport</value> </property> </bean> <!--定时器设定起动频率&启动时间我设的是每5秒起动一次 (0 0 4 * * ?每日四点起动....)--> <bean id="cronReportTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail"><ref bean="scheduledReportJobDetail"/> </property> <property name="cronExpression"><value>10,15,20,25,30,35,40,45,50,55 * * * * ?</value> </property> </bean> </beans>
测试
package com.spring.helloworld;
import java.io.FileNotFoundException;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;
import com.spring.hellow.LogInit;
import com.spring.hellow.QuestException;
public class TaskApp {
public static void main(String[] args) throws BeansException, FileNotFoundException, QuestException, InterruptedException {
new LogInit("WEB-INF/classes/com/spring/helloworld/log4j.properties");
BeanFactory factory = new XmlBeanFactory(new FileSystemResource(
"WEB-INF/classes/" +
"com/spring/helloworld/" +
"helloworld.xml"));
factory.getBean("z");//为什么必须用这个方法触发呢不触发为什么不行呢?
}
}
评论
抛出异常的爱
2008-07-15
谢谢
sbe_steels
2008-07-05
在web.xml配置spring的监听器就可以,如果还要硬编码的形式来获取Scheduler,可能不能完全成为定时器,或则定时任务。
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
julycool
2007-09-05
设置lazy-init为false
Godlikeme
2006-12-24
factory.getBean("z");//为什么必须用这个方法触发呢不触发为什么不行呢?
因为这个bean没有加载,scheduler没有实例化。如果自定义scheduler,还需要显示调用scheduler.start().或者再配置文件中声明。
因为这个bean没有加载,scheduler没有实例化。如果自定义scheduler,还需要显示调用scheduler.start().或者再配置文件中声明。
发表评论
- 浏览: 216120 次
- 性别:

- 来自: 北京

- 详细资料
搜索本博客
我的相册
长椅
共 39 张
共 39 张
最近加入圈子
链接
最新评论
-
到底要招什么样子的人?
那到底要什么样的人啊?你的重点呢?你想表达什么?
-- by xiaoyi829 -
到底要招什么样子的人?
努力吧!什么都是从不懂到懂,懂到精通!
-- by ada1230 -
DBA数据库字典
懒人。。。半仙。。。
-- by YuLimin -
天狗食日
看了。。。英雄(美剧)。。。。 之后就非常想要见识一下日食了 谢谢
-- by 抛出异常的爱 -
天狗食日
按照月亮运行规律来讲,一个月就会出现一次日食,并且今年出现日食时间和明年差不多, ...
-- by ddd






评论排行榜