http://m.blog.csdn.net/article/details?id=50945311
首先在配置文件頭部的必須要有:
xmlns:task="http://www.springframework.org/schema/task"
1
其次xsi:schemaLocation必須為其添加:
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task.xsd
1
2
然后spring掃描過程必須涵蓋定時任務類所在的目錄:
<context:component-scan base-package="com.xx.xx" />
1
com.xx.xx屬於定時任務類的父級甚至更高級
然后設置動作啟用定時任務
<task:annotation-driven/>
1
最后設置任務類
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
@Lazy(value=false)
public class MyQuartzs {
@Scheduled(cron = "*/5 * * * * ?")//每隔5秒執行一次
public void test() throws Exception {
System.out.println("Test is working......");
}
//@Scheduled(cron = "0 0 1 * * ?")//每天凌晨1點整
//@Scheduled(cron = "0 30 0 * * ?")//每天凌晨0點30分
//@Scheduled(cron = "0 */60 * * * ?")//1小時處理一次
}
