SpringMVC 定时任务的配置有两种
第一种:
使用 @Scheduled(cron="0 0 1 * * ?") 注解
同时在配置文件中引入
xmlns:task="http://www.springframework.org/schema/task"
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd">
<!-- 计划任务配置,用 @Service @Lazy(false)标注类,用@Scheduled(cron = "0 0 1 * * ?")标注方法 -->
<task:executor id="executor" pool-size="10"/> <task:scheduler id="scheduler" pool-size="10"/>
<task:annotation-driven scheduler="scheduler" executor="executor" proxy-target-class="true"/>
cron="0 0 1 * * ?" 表示定时执行的时间(每天凌晨1点)