三步搞定Spring3.0 quartz 定时器执行定时任务

原文地址:http://www.peiyin520.com/graphDetail.jsp?gid=8

1.新建执行定时任务的类与方法

public class TaskPlan {
	public void <span style="color:#ff0000;">test</span>(){
		System.out.println(new Date().toString());
	}
}


2.新建配置文件quartz.xml文件

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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"
  xmlns:task="http://www.springframework.org/schema/task"
  xsi:schemaLocation="http://www.springframework.org/schema/beans  
  http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
  http://www.springframework.org/schema/task  
  http://www.springframework.org/schema/task/spring-task-3.0.xsd">
  <!--  <task:annotation-driven /> 定时器开关-->
  <bean id="taskPlan" class="<span style="color:#009900;">com.mofei.mm.task.TaskPlan</span>"></bean> <span style="color:#ff9900;"><span style="font-size:14px;"><!--</span>填类对应路径<span style="font-size:14px;">--></span></span>
  <task:scheduled-tasks>
    <task:scheduled ref="taskPlan" method="<span style="color:#ff0000;">test</span>" cron="5/3 * * * * ?" /> <span style="font-size:14px;"></span><pre name="code" class="html"><span style="color:#ff9900;"><span style="font-size:14px;"></span></span><pre name="code" class="html"><span style="color:#ff9900;"><!--填写对应定时执行方法名,cron如何填写请百度quartz时间配置说明--></span>

 </task:scheduled-tasks></beans> 
 


3.配置quartz,xml在web.xml中的加载路径

<!-- spring加载文件 -->

<context-param>
	<param-name>contextConfigLocation</param-name>
	<param-value>classpath:applicationContext.xml<span style="color:#ff0000;">,classpath:quartz.xml</span></param-value>
</context-param>



原文地址:http://www.peiyin520.com/graphDetail.jsp?gid=8



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值