1.首先加入上篇文章中所需要的jar包
2. xmlns 多加下面的内容、
xmlns:task="http://www.springframework.org/schema/task"
3.xsi:schemaLocation
http://www.springframework.org/schema/task2. xmlns 多加下面的内容、
xmlns:task="http://www.springframework.org/schema/task"
3.xsi:schemaLocation
http://www.springframework.org/schema/task/spring-task-3.1.xsd ;
4.springxml中加入<task:annotation-driven/>
5. 加入<context:component-scan base-package="com.test"/>
6.实现类
@Component
public class ToPtAccountTime{
@Scheduled(cron="0 10-55 17 * * ? ")
public void perform(){ //执行报表统计入口函数
//业务逻辑
System.out.println("开始执行报表的业务逻辑了----现在的时间是--"+new Date());
System.out.println("xxxxxx");
}
}
或者直接 spring.xml <task:scheduled ref="TaskTimer" method="toPtAccountDay" cron="0 * 10 * * ?"/>
5. 加入<context:component-scan base-package="com.test"/>
6.实现类
@Component
public class ToPtAccountTime{
@Scheduled(cron="0 10-55 17 * * ? ")
public void perform(){ //执行报表统计入口函数
//业务逻辑
System.out.println("开始执行报表的业务逻辑了----现在的时间是--"+new Date());
System.out.println("xxxxxx");
}
}
或者直接 spring.xml <task:scheduled ref="TaskTimer" method="toPtAccountDay" cron="0 * 10 * * ?"/>
本文介绍如何在Spring框架中配置并实现定时任务。主要内容包括:添加必要的jar包,配置XML命名空间及schemaLocation,使用<task:annotation-driven/>启用注解支持,通过@Component和@Scheduled注解创建定时任务类,以及在spring.xml中直接定义定时任务。
1213

被折叠的 条评论
为什么被折叠?



