Spring定时任务@Scheduled注解使用
一、配置spring.xml配置文件
1、在xmlns加入:
xmlns:task="http://www.springframework.org/schema/task"
2、在xsi:schemaLocation中加入:
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-4.2.xsd
3、配置定时任务:
<!-- 定时任务 -->
<task:annotation-drivenexecutor="executor" scheduler="scheduler"/>
<task:executorid="executor" pool-size="5" />
<task:schedulerid="scheduler" pool-size="5" />
<context:annotation-config/>
<beanclass="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
<context:component-scanbase-package="com.ropeok"/>
二、实现类注解配置
1、实现类加@ Component;
2、方法上加@Scheduled