spring xml 定时任务
来源:互联网 发布:编程更改组策略 编辑:程序博客网 时间:2024/06/09 16:08
启动服务器,根据时间设置规则,执行相应操作
想了解时间规则(click me)
一、写一个操作类
1.记住类路径
2.记住类名和方法名
二、修改xml文件
1. 创建一个applicationContext.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:p="http://www.springframework.org/schema/p"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"></beans>2. 将操作类配置进去(完整类路径名)
<bean id="myTimer" class="com.timer.MyTimer"></bean>3. 定时器配置(类名和方法名)
<!-- 定时器配置 --><bean id="timeDitail"class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"><property name="targetObject" ref="myTimer"></property><property name="targetMethod" value="showtime"></property></bean>4. 定义时间间隔触发器(每五秒触发一次)
<bean id="timeTigger" class="org.springframework.scheduling.quartz.CronTriggerBean"><property name="jobDetail" ref="timeDitail"></property><property name="cronExpression"><value>*/5 * * * * ?</value></property></bean>5. 管理并启动触发器
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"><property name="triggers"><list><ref bean="timeTigger" /></list></property></bean>
添加如下内容
<context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml</param-value></context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener>
四、导入jar包
1. spring
2.quartz
3.commons-logging和commons-collections
4.log4j和slf4j
五、启动tomcat,在Console窗口看到如下结果,并每五秒会有一条新纪录
完整项目下载:http://download.csdn.net/detail/flykos/9698965
0 0
- spring xml 定时任务
- Spring定时任务-xml实现
- spring定时任务applicationContext.xml中配置
- spring定时任务-基于注解和xml
- 基于xml配置的spring定时任务
- spring多个定时任务job.xml配置
- spring定时任务之quartz基于xml开发
- Spring计划任务(定时任务)
- Spring 定时任务功能
- Spring 定时任务实现
- spring执行定时任务
- spring执行定时任务
- spring中的定时任务
- spring多定时任务
- Spring+Quartz定时任务
- spring的定时任务
- spring 定时任务
- Spring 定时任务功能
- This email address is not valid for use as an Apple ID.
- Android 自定义adapter(二)
- 字符设备驱动应用---LED设备驱动实现
- JavaWeb学习总结---JSP原理
- 解决ScrollView.setOnScrollChangeListener()API23以下不可用
- spring xml 定时任务
- s5pv210 IROM启动流程详解
- 如何让button保持点击状态
- windows下erlang环境搭建和创建第一个简单例子
- Android-幻灯片播放
- ORA-00604: 递归 SQL 级别 1 出现错误 ORA-01653: 表 SYS.AUD$ 无法通过 8192 (在表空间 SYSTEM 中) 扩展
- MySQL 教程
- 【Redis缓存机制】9.快照持久化和AOF持久化
- httpclient4.5获取和设置cookie