1.在SpringMVC配置文件中添加
xmlns:task="http://www.springframework.org/schema/task"
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.2.xsd
<task:annotation-driven />
<context:component-scan base-package="com.vrveis.roundTrip.task" />
如图所示:
java代码示例
package com.vrveis.roundTrip.task;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class FlightTrainTask {
//@Scheduled(cron = "0/5 * * * * ? ") // 间隔5秒执行
@Scheduled(fixedRate = 60 * 1000)//每60秒执行一次
public void taskCycle() {
System.out.println("使用SpringMVC框架配置定时任务");
}
}