scheduled的使用注解的方式进行调度

先要配置spring.xml

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:annotation-config/>
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
<context:component-scan base-package="com.zyt.test"/>

调用

import org.springframework.stereotype.Component;  

@Component
public class TestService {
    // 5秒钟执行一次
@Scheduled(cron="0/5 * * * * ? ") //每5秒执行一次
    public void test(){
System.out.println("每隔五秒打印一次");
}
}

@Scheduled 注解要写在实现方法上

定时器的任务方法不能有返回值(如果有返回值的话,spring初始化的时候会报错,需要设定一个proxytargetclass的某个值为true,请自行百度google)

剩下的就是corn表达式了

请自行百度google

最新文章

  1. Linux - Tips
  2. UITextFiled,UITextView长度限制
  3. vim——打开多个文件、同时显示多个文件、在文件之间切换
  4. [转]Ubuntu下使用Jni开发例子
  5. iOS prototype Cells
  6. HDU 1978 How many ways(动态规划)
  7. OPatch failed with error code 73
  8. codeforces Minesweeper 1D
  9. SSAS父子层次结构的增强-UnaryOperatorColumn属性
  10. Android动态加载技术(插件化技术)
  11. spring里的事物设置
  12. [题目] luogu P2061 [USACO07OPEN]城市的地平线City Horizon
  13. MySQL 术语
  14. HTML5 图片宽高自适应,居中裁剪不失真
  15. mybatis分页插件Mybatis_PageHelper 简单案例
  16. Okhttp3 使用和原理(DEMO)
  17. WPF导航总结
  18. C#扩展一个现有的类
  19. unicode编码转汉字
  20. bzoj3172: [Tjoi2013]单词 ac自动机

热门文章

  1. Kafka 集群在马蜂窝大数据平台的优化与应用扩展
  2. SpringDataJpa多条件查询代码封装
  3. js中的事件委派
  4. 《吊打面试官》系列-ArrayList
  5. surging 社区版本支持.net core 3.1
  6. Java手写数组栈
  7. MySQL数据库保存emoji表情
  8. ArcEngine 创建要素,删除要素,生成网格,渲染图层(VB)
  9. mysql索引创建和使用细节(二)
  10. 关于将vs项目推到GitHub上遇到的问题