您的位置:首页 > 编程语言 > Java开发

spring 注解实现 定时任务

2016-04-27 11:01 357 查看
第一步:在spring配置文件中引入

xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation中引入下面的
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd[/code] 
第二步:配置文件中 引入 定时任务注解

<task:annotation-driven/>
<context:annotation-config/>
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
<context:component-scan base-package="com.test"/>
其中 base-package 定义要扫描的基础包
 

第三步:创建业务定时任务类

注意:

1.该类要加上@Component 注解标签

2.方法上加上@Scheduled(cron="0/5 * *  * * ? ")注解标签

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: