基于xml配置的spring定时任务
来源:互联网 发布:timeline软件 中文 编辑:程序博客网 时间:2024/04/29 23:57
基于xml配置的spring定时任务
首先写springtask的执行定时任务的测试类,具体代码如下:
import org.springframework.stereotype.Service;@Servicepublic class SpringTaskDemo { public void task1() { System.out.println("这是定时器的第一个定时任务。。。。。"+df.format(new Date())); System.out.println("每分钟执行一次"); } public void task2() { System.out.println("这是定时器的第二个定时任务。。。。。"+df.format(new Date())); System.out.println("每两分钟执行一次"); }}
然后在spring配置中加入task的描述,具体配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
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/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd">
</beans>
最后配置具体的定时任务,代码如下: <!-- 定时任务配置开始 -->
<bean id="springTaskDemo"
class="com.leixin.csdn.springtaskdemo.SpringTaskDemo" />
<task:scheduled-tasks>
<task:scheduled ref="springTaskDemo" method="task1" cron="0 0/1 * * * ?" />
<task:scheduled ref="springTaskDemo" method="task2" cron="0 0/2 * * * ?" />
</task:scheduled-tasks>
<!-- 定时任务配置结束 -->
最后运行的结果如图所示:
附上源码下载地址:
单纯的spring开启定时任务:http://yunpan.cn/c6tmQNFuL5cME (提取码:1b55)
SpringMVC+Mybatis+Spring+Maven整合的定时任务:http://yunpan.cn/c6tm3aYDWrxja (提取码:03d2)
- 基于xml配置的spring定时任务
- spring自带的定时任务功能,基于注解和xml配置
- spring自带的定时任务功能,基于注解和xml配置
- spring自带的定时任务功能,基于注解和xml配置
- spring自带的定时任务功能,基于注解和xml配置
- spring自带的定时任务功能,基于注解和xml配置
- spring自带的定时任务功能,基于注解和xml配置
- spring自带的定时任务功能,基于注解和xml配置
- spring自带的定时任务功能,基于注解和xml配置
- spring定时任务-基于注解和xml
- 基于spring的quartz定时任务的配置详述
- spring定时任务_基于配置
- spring定时任务applicationContext.xml中配置
- spring定时任务的配置
- spring定时任务的配置
- spring的定时任务配置
- Spring的定时任务配置
- spring 定时任务的配置
- elasticsearch性能测试工具rally深入详解
- HDU 4460 Friend Chains(BFS)
- centos7下安装lnmp
- POJ 3274 Gold Balanced Lineup
- 怎样实现安卓中侧滑功能
- 基于xml配置的spring定时任务
- UVa OJ 1152 - 4 Values whose Sum is 0
- JS中defer和async的区别
- hdu 5808 Price List Strike Back 分治
- java总结I/O流
- 郝夫曼树
- MFC---AnimateWindow实现窗口动画效果
- 动态广播和静态广播的区别
- 机器人定位 - 蒙特卡罗定位(直方滤波算法)