springmvc 配置定時器
阿新 • • 發佈:2018-12-21
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
2、配置任務掃描
<task:annotation-driven />
3、配置掃描任務位置
<!-- 掃描任務 --> <context:component-scan base-package="com.vrveis.roundTrip.task" />
4、demo
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秒執行 public void taskCycle() { System.out.println("使用SpringMVC框架配置定時任務"); } }
5、cron表示式線上生成器