在Spring3中使用注解(@Scheduled)创建计划任务(最简化配置)
2016-06-22 14:57
573 查看
一、配置文件
beans中加入:
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.0.xsd
再加入:
<task:annotation-driven/>
二、java
beans中加入:
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.0.xsd
再加入:
<task:annotation-driven/>
二、java
package com.springmvc.tesk; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @Component public class SpringTaskDemo { @Scheduled(fixedDelay = 5000) void doSomethingWithDelay(){ System.out.println("I'm doing with delay now!"); } @Scheduled(fixedRate = 5000) void doSomethingWithRate(){ System.out.println("I'm doing with rate now!"); } @Scheduled(cron = "0/5 * * * * *") void doSomethingWith(){ System.out.println("I'm doing with cron now!"); } }
相关文章推荐
- ++i,i++,--i和i--的区分
- java类的加载机制
- java类的加载机制
- java类的构造方法可以直接调用该类中已有的方法。
- java 属性
- MyEclipse配置Maven插件
- Spring10种常见异常解决方法
- 【转载】Java 对象之死
- s 4000 truts2的校验
- Java正则表达式的使用
- Spring Boot 实践折腾记(六):Spring Boot中的容器配置和SSL支持
- Springmvc 与 MyBatis的整合(四)service
- java设计模式-单例模式
- java 继承 讲解
- 学习整合hibernate springmvc spring的 心得(3)
- eclipse动画快捷键
- Spring Mvc与struts2区别
- java自己用到的工具类
- java单个文件复制,递归删除、复制目录下所有内容,递归创建文件夹,.7z文件解压等
- java中的三元运算符没那么肤浅