首先要引入xsd:
<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">
<!--
这里加入了
xmlns:task="http://www.springframework.org/schema/task"
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd
-->
<task:annotation-driven /> <!-- 定时器开关-->
<bean id="taskTest" class="com.jungle.test.TaskTest"></bean>
<task:scheduled-tasks>
<!-- 这里表示的是从第五秒开始 ,每三秒执行一次 (而不是 三分之五 秒执行一次) -->
<task:scheduled ref="taskTest" method="say" cron="5/3 * * * * ?" />
<task:scheduled ref="taskTest" method="hello" cron="5/3 * * * * ?"/>
</task:scheduled-tasks>
普通java类:
package com.jungle.test;
import java.util.Date;
public class TaskTest {
public void say() {
System.out.println("这个真好用!!!" + new Date());
}
public void hello(){
System.out.println("hello!!!");
}
}