原文地址: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"?></task:scheduled-tasks></beans>
<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>
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