spring整合quartz
来源:互联网 发布:阿里云服务器使用手册 编辑:程序博客网 时间:2024/05/20 18:50
小试spring整合quartz
在这里就不写别的spring配置文件了,就只写一个quartz_config.xml 作为spring的配置文件
我整合的时候用的是spring2.5的,不过我用3.0的jar也是一样可行的
第一步:web.xml 里面加载spring的listener 和 quartz_config.xml
<context-param><param-name>contextConfigLocation</param-name><param-value>/WEB-INF/quartz_config.xml</param-value></context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
第二步 就是配置quartz_config.xml
<?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:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> <!-- helloworld --><bean id="hellWordTaskTimerBean" class="com.yeshun.quartz.HelloWordTask" /><bean id="hellWordTaskTimerMethod" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"><property name="targetObject" ref="hellWordTaskTimerBean" /> <!-- targetMethod 配置定时执行的方法名 --> <property name="targetMethod" value="executeAction" /><property name="concurrent" value="false" /></bean> <!-- Quartz中有几种triggers,Spring提供两个子类 CronTriggerBean 和 SimpleTriggerBean (补充)--> <bean id="hellWordTaskTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"><property name="jobDetail" ref="hellWordTaskTimerMethod" /><property name="cronExpression" value="0/10 * * * * ?" /></bean><bean id="helloWordTaskTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean"> <property name="jobDetail" ref="hellWordTaskTimerMethod" /><!-- 延迟10秒启动 --> <property name="startDelay" value="10000" /> <!-- 每60秒执行一次 --> <property name="repeatInterval" value="60000" /> </bean> <bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"><property name="triggers"><list><ref bean="hellWordTaskTrigger" /></list></property></bean></beans>
这样一看就很明了了吧
同样我只配置了一个定时作业任务 ,可以配置多个,然后加到list里面
<property name="triggers"><list><ref bean="hellWordTaskTrigger" /></list></property>
第三部 配置定时作业的类 需要实现spring的QuartzJobBean接口 里面可以写上配置文件targetMethod里面的方法
package com.yeshun.quartz;import org.quartz.JobExecutionContext;import org.quartz.JobExecutionException;import org.springframework.scheduling.quartz.QuartzJobBean;public class HelloWordTask extends QuartzJobBean {public void executeAction() {//to do something...System.out.println("hello world!!");}@Overrideprotected void executeInternal(JobExecutionContext arg0)throws JobExecutionException {// TODO Auto-generated method stub}}
那么启动项目后 每隔十秒就自动打印hello world!!
附上源码地址点击打开链接
- Spring-----Spring整合Quartz
- spring整合quartz
- spring整合quartz
- spring整合quartz
- Spring整合quartz配置
- Spring 整合quartz
- Spring整合quartz
- Spring整合Quartz示例
- spring整合quartz
- spring quartz框架整合
- spring跟QuartZ整合
- Spring-quartz整合
- Quartz 整合Spring 小试牛刀
- spring整合quartz
- spring整合quartz
- Spring+Quartz整合
- Spring整合Quartz
- spring和quartz整合
- MOVE语句。
- READ1.
- )::WaitForSingleObject
- 黑马程序员--java多线程
- 所谓经验,半数扯淡
- spring整合quartz
- Linux RTC 驱动模型分析
- android 修改文件属性(U960S删除快门声实例)
- 对在校学生的想从事嵌入式行业的几点建议
- spring 依赖注入一
- While循环
- WhileTest
- 蓝桥杯—2012 河南省初赛——————比酒量
- WhileTest1