使用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 添加定时任务注解
添加注解扫描的包
<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 百度有很多
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 百度有很多
相关文章推荐
- 使用spring @Scheduled注解执行定时任务、
- 使用spring @Scheduled注解执行定时任务、
- quartz 框架定时任务,使用spring @Scheduled注解执行定时任务
- 使用spring @Scheduled注解执行定时任务
- 使用spring @Scheduled注解执行定时任务
- 使用spring @Scheduled注解执行定时任务
- 使用spring @Scheduled注解执行定时任务、
- 使用spring @Scheduled注解执行定时任务
- 使用spring @Scheduled注解执行定时任务
- 使用spring @Scheduled注解执行定时任务
- 使用spring @Scheduled注解执行定时任务
- 使用spring @Scheduled注解执行定时任务
- 使用spring @Scheduled注解执行定时任务、
- 使用spring @Scheduled注解执行定时任务
- 使用spring @Scheduled注解执行定时任务
- 使用spring @Scheduled注解执行定时任务、
- 使用spring @Scheduled 注解执行定时任务
- 使用spring @Scheduled注解执行定时任务
- 使用spring @Scheduled注解执行定时任务
- 使用spring @Scheduled注解执行定时任务