(一)在spring.xml里加入task的命名空间
xmlns:task="http://www.springframework.org/schema/task" http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task.xsd
(二)启用注解驱动的定时任务
<task:annotation-driven executor="executor" scheduler="scheduler"/>
(三)配置定时任务的线程池
推荐配置线程池,若不配置多任务下会有问题。后面会详细说明单线程的问题。
<task:scheduler id="scheduler" pool-size="10"/>
该处的id值和(二)中的scheduler="scheduler"对应
(四)写我们的定时任务