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

SpringMVC的定时任务的配置

2015-12-15 15:32 471 查看
1、在spring-mvc.xml中填写如下内容:

xmlns:task="http://www.springframework.org/schema/task"


2、在spring-mvc.xml中填写如下内容:

http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd[/code] 
3、在spring-mvc.xml中填写如下内容:

<context:component-scan base-package="com.bms.timing.task"/>


其中:com.bms.timing.task"是自己定义的定时任务所在的包

4、定义定时任务

package com.bms.timing.task;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class MyTask {

@Scheduled(cron="0/5 * * * * ? ") //间隔5秒执行
public void taskCycle(){

System.out.println("hello world!!");
}

}


其中:@Scheduled(cron="0/5 * * * * ? ") 用来设计定时任务的执行频率



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