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

使用spring @Scheduled注解执行定时任务

2015-04-28 15:03 701 查看
spring.xml 的 xmlns 添加:

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 添加定时任务注解

<task:annotation-driven/>


添加注解扫描的包
<context:component-scan base-package="com.demo.service"/>

java文件
package com.demo.service;

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

@Component
public class DemoService {
@Scheduled(cron="0/5 * * * * ? ")
public void test(){
System.out.println("test is run.");
}
}
至于cron 百度有很多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  JAVA spring schema