1.Xml配置 Spring-job.xml 并在 Spring-Application.xml中Import

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.1.xsd"> <description>Spring Configuration</description>
<context:component-scan base-package="包的根目录例:com.xx.xx"/>
<!-- 配置任务线性池 -->
<task:executor id="executor" pool-size="10" />
<task:scheduler id="scheduler" pool-size="10"/>
<task:annotation-driven scheduler="scheduler" executor="executor" proxy-target-class="true"/>
<!-- 如果类文件中没有使用@Scheduled ,可以使用下面的配置 -->
<!--<task:scheduled-tasks scheduler="scheduler">
<task:scheduled ref="TestJob" method="test" cron="0/1 * * * * ?"/>
</task:scheduled-tasks>-->
</beans>

2.类文件TASK.java

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; @Component("TestJob")
public class ATask{
@Scheduled(cron = "0 9 16 * * ?")//每隔5秒隔行一次
public void test(){
System.out.println("job1 开始执行。。。。");
}
}

然后就可以了;

原文地址:https://blog.csdn.net/zhulin2012/article/details/51916612

最新文章

  1. java基础小知识
  2. 【GoLang】GoLang 错误处理 -- 异常处理思路示例
  3. jQuery 预习视频
  4. SpringMvc中的反射
  5. mybatis多对一关联的两种方式
  6. html5 meta标签属性整理
  7. [OI笔记] 最长上升子序列与网络流建模
  8. NSNotificationCenter 传对象
  9. jQuery背景跟随鼠标移动的网页导航
  10. .NET下,关于文件夹权限设置的小细节
  11. “等一下,我碰!”——常见的2D碰撞检测
  12. Elasticsearch Kibana查询语法
  13. c/c++ 网络编程 UDP 用if_nameindex和ioctl取得主机网络信息
  14. Go 初体验 - 常量 与 iota
  15. Quartz框架学习(1)—核心层次结构
  16. keras中VGG19预训练模型的使用
  17. es7新特性 includes用法
  18. jenkins 工作空间的目录
  19. Android Apollo MQTT入门
  20. Alfred修改内置Terminal为iTerm

热门文章

  1. CSharp遗传算法求解背包问题
  2. python网络编程(九)
  3. Coins [POJ1742] [DP]
  4. Yii2 数据库sql查询
  5. ajax-异步加载片段
  6. bzoj 1006
  7. [原创]浅谈移动互联网App兼容性测试
  8. [转]开源.net 混淆器ConfuserEx介绍
  9. 本机ip、127.0.0.1和0.0.0.0区别及内环流量
  10. linux 系统下使用socket进行本地进程间通信