一、配置文件
beans中加入:
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation中加入:
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
再加入:
<task:annotation-driven/>
二、java
package com.springmvc.tesk;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class SpringTaskDemo {
@Scheduled(fixedDelay = 5000)
void doSomethingWithDelay(){
System.out.println("I'm doing with delay now!");
}
@Scheduled(fixedRate = 5000)
void doSomethingWithRate(){
System.out.println("I'm doing with rate now!");
}
@Scheduled(cron = "0/5 * * * * *")
void doSomethingWith(){
System.out.println("I'm doing with cron now!");
}
}