1.applicationContext.xml 中 加入task 的声明与xsd

1
xmlns:task="http://www.springframework.org/schema/task"
1
http://www.springframework.org/schema/task  http://www.springframework.org/schema/task/spring-task-4.0.xsd

配置中加入

1
<task:annotation-driven/>

这个是用来启用自动的注解解析。

2.编写POJO

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
@Component 
public class DailyPiracyJob {   
    @Scheduled(cron = "0 0 23 * * ?")
    public void print() throws Exception {
    system.out.println(干点你想干的事!);      
    }
}

  @Compont 注解,是让Spring context 可以扫描到,并自动注入需要的bean

@Scheudle 核心注解,不能有返回值,cron是定义了任务运行的间隔,具体,请参考网上其他教程

需要注意的是,在applicationContext.xml中不能启用 default-lazy-init=“true”,否则注解会失效

Spring 定时任务的配置的更多相关文章

  1. spring定时任务的配置

    定时任务配置分为三个步骤: 1.定义任务 2.任务执行策略配置 3.启动任务 1.定义任务 <!--要定时执行的方法--> <bean id="testTaskJob&qu ...

  2. spring定时任务的配置使用

    spring的定时任务配置分为三个步骤: 1.定义任务 2.任务执行策略配置 3.启动任务 1.定义任务 <!--要定时执行的方法--> <bean id="testTas ...

  3. spring 5.x 系列第22篇 —— spring 定时任务 (代码配置方式)

    源码Gitub地址:https://github.com/heibaiying/spring-samples-for-all 一.说明 1.1 项目结构说明 关于任务的调度配置定义在ServletCo ...

  4. spring 5.x 系列第21篇 —— spring 定时任务 (xml配置方式)

    源码Gitub地址:https://github.com/heibaiying/spring-samples-for-all 一.说明 1.1 项目结构说明 关于任务的调度配置定义在springApp ...

  5. spring定时任务的配置式与注解式

    在定时任务配置文件中添加内容: <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi=&q ...

  6. spring 定时任务参数配置详解

    注:本文摘自<Quartz Cron 触发器 Cron Expression 的格式>http://blog.csdn.net/yefengmeander/article/details/ ...

  7. spring定时任务配置,以及不执行的解决办法

    前几天,同事问了我一个问题,我告诉他用spring的定时任务解决,并给他配置了spring的定时任务.当时随便找了一个bean写了一段代码,验证定时任务正确执行后,就没再管,昨天下午,同事写代码的时候 ...

  8. spring 定时任务配置

    1.(易)如何在spring中配置定时任务? spring的定时任务配置分为三个步骤: 1.定义任务 2.任务执行策略配置 3.启动任务 (程序中一般我们都是到过写的,直观些) 1.定义任务 < ...

  9. spring Quartz多个定时任务的配置

    Quartz多个定时任务的配置 1,配置文件与spring整合,需要在spring 的总配置中一入或者在web.xml中spring监听中加上 ztc_cp-spring-quartz.xml 注:定 ...

随机推荐

  1. 关于viewport的研究

    昨天项目中用到了适应移动端显示的viewport,一般的使用方式如下: <meta name="viewport" content="width=device-wi ...

  2. Uva 1220,Hali-Bula 的晚会

    题目链接:https://uva.onlinejudge.org/external/12/1220.pdf 题意: 公司n个人,形成一个数状结构,选出最大独立集,并且看是否是唯一解. 分析: d(i) ...

  3. JavaScript获取元素尺寸和大小操作总结

    一.获取元素的行内样式 复制代码 代码如下: var obj = document.getElementById("test"); alert(obj.height + " ...

  4. sql 百万级数据库优化方案

    转自http://blog.sina.com.cn/s/blog_724cd89d0100ppcz.html 1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉 ...

  5. 命令行下运行php的方法和技巧

    linux中直接用"php"命令来执行php文件 一般在linux命令行下运行php文件的代码: XML/HTML代码 linux下执行:#php安装路径 -f php文件路径 例 ...

  6. 企业邮件服务器被列入RBL,申请撤销PBL指控

    1.登录[url]http://www.spamhaus.org/pbl/index.lasso[/url],在红框中输入企业电子邮件服务器MX记录地址:

  7. 对Spring <context:annotation-config/>的理解

    在基于主机方式配置Spring的配置文件中,你可能会见到<context:annotation-config/>这样一条配置,他的作用是向 Spring 容器注册 AutowiredAnn ...

  8. [转]What you need to know about transimpedance amplifiers – part 1

    Transimpedance amplifiers (TIAs) act as front-end amplifiers for optical sensors such as photodiodes ...

  9. 折半查找&clock函数

    #include <stdio.h>#include <time.h> #define CLOCKS_PER_SEC ((clock_t)1000) int binsearch ...

  10. nancy中的诊断功能面板1

    nancyfx中有一项 诊断功能 ,可以查看网站的基本信息和其他相关信息,还包括查看会话信息,请求输出信息等. 假设你已经安装完了nancyfx.现在开始使用诊断功能: 一 安装 在你的Bootstr ...