Spring3.0以后自主开发的定时任务工具SpringTask,可以将它比作一个轻量级的 Quartz,使用起来很简单,除Spring相关的包外不需要额外的包,支持注解和 配置文件两种形式。
代码示例
1、配置文件 - 开启任务调度
<?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:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd">
<!--开启任务调度-->
<task:annotation-driven></task:annotation-driven>
</beans>
2、编写调度代码
@Component
@EnableScheduling
public class TestTask {
// 该注解中为Cro