一、建立定时类php
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @Component public class FlightTrainTask { @Scheduled(cron = "0/5 * * * * ? ") // 间隔5秒执行 public void taskCycle() { System.out.println("使用SpringMVC框架配置定时任务"); } }
二、在spring的配置xml文件中开启定时选项spring
<task:annotation-driven /> <context:component-scan base-package="com.timer" /> //定时器所在文包