spring-task.xml

<?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:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.1.xsd"> <!-- 默认扫描的包路径 -->
<context:component-scan base-package="*" />
<!-- springMVC 定时器开关 -->
<task:annotation-driven />
</beans>

web.xml(在web.xml中加入以下代码)

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/spring-task.xml</param-value>
</context-param>

MidTask.java

package com.henu.task;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class MidTask { /**
* 定时计算。每隔五秒执行一次
*/
@Scheduled(cron = "0/5 * * * * ?")
public void show(){
System.out.println("task1");
}
/**
* 定时计算。每隔十秒执行一次
*/
@Scheduled(cron = "0/10 * * * * ?" )
public void zol(){
System.out.println("task2");
}
}

Spring定时器注解配置的更多相关文章

  1. [spring-framework]Spring定时器的配置和使用

    开发中我们常常会做一些定时任务,这些任务有开始时间,并会按一定的周期或规则执行.如此我们在Java程序开发中使用定时器来处理定时任务. <!-- MessageRequestTask类中包含了m ...

  2. JavaWeb_(Spring框架)注解配置

    系列博文 JavaWeb_(Spring框架)xml配置文件  传送门 JavaWeb_(Spring框架)注解配置 传送门 Spring注解配置 a)导包和约束:基本包.aop包+context约束 ...

  3. spring aop注解配置

    spring aop是面向切面编程,使用了动态代理的技术,这样可以使业务逻辑的代码不掺入其他乱七八糟的代码 可以在切面上实现合法性校验.权限检验.日志记录... spring aop 用的多的有两种配 ...

  4. java框架之Spring(2)-注解配置IOC&AOP配置

    注解配置IoC 准备 1.要使用注解方式配置 IoC,除了之前引入的基础 jar 包,还需要引入 spring-aop 支持包,如下: 2.在 applicationContext.xml 中引入 c ...

  5. Spring自定义注解配置切面实现日志记录

    一: spring-mvc.xml: <!--配置日志切面 start,必须与mvc配置在同一个配置文件,否则无法切入Controller层--><!-- 声明自动为spring容器 ...

  6. spring定时器的配置

    首先,新建一个java项目,下面导入需要的jar包: 这里有你需要的jar包哦. jar包下载 在src文件夹下,新建一个applicationContext.xml文件 <?xml versi ...

  7. Spring纯注解配置

    待改造的问题 我们发现,之所以我们现在离不开 xml 配置文件,是因为我们有一句很关键的配置: <!-- 告知spring框架在,读取配置文件,创建容器时,扫描注解,依据注解创建对象,并存入容器 ...

  8. Spring的注解配置与XML配置之间的比较

    注释配置相对于 XML 配置具有很多的优势: 它可以充分利用 Java 的反射机制获取类结构信息,这些信息可以有效减少配置的工作. 如:使用 JPA 注释配置 ORM 映射时,我们就不需要指定 PO ...

  9. Spring(四)注解配置Ioc

    原文链接:http://www.orlion.ga/216/ 一.@Autowired beans.xml配置成如下: <?xml version="1.0" encodin ...

随机推荐

  1. Codeforces Round #292 (Div. 1) C - Drazil and Park

    C - Drazil and Park 每个点有两个值Li 和 Bi,求Li + Rj (i < j) 的最大值,这个可以用线段树巧妙的维护.. #include<bits/stdc++. ...

  2. LaTex 小技巧

    首行缩进 参考:小技巧之--首行缩进 %-------------------------------------------------------------------------------- ...

  3. Git gitconfig 配置

    difftool: [diff] tool = bc4 algorithm = histogram [difftool] prompt = false [difftool "bc4" ...

  4. SpringMVC框架 注解 (转)

    原文地址:http://www.cnblogs.com/yjq520/p/6734422.html 1.@Controller @Controller 用于标记在一个类上,使用它标记的类就是一个Spr ...

  5. centos7-硬盘坏道检测

    #检测坏道命令,结果输出到 /home/badblocks.log badblock -s -v -o /home/badblocks.log /dev/sdb1 [注]:硬盘损坏程度不同,block ...

  6. 【LeetCode】shell

    195. Tenth Line 输出file.txt中的第十行 答案: # Read from the file file.txt and output the tenth line to stdou ...

  7. openvpn部署centos7

    [root@openvpn ~]# cat /etc/redhat-release CentOS Linux release 7.3.1611 (Core) 安装包 yum upgrade yum i ...

  8. bzoj 4034: [HAOI2015]T2

    4034: [HAOI2015]T2 Description 有一棵点数为 N 的树,以点 1 为根,且树点有边权.然后有 M 个 操作,分为三种: 操作 1 :把某个节点 x 的点权增加 a . 操 ...

  9. @SuppressWarning 抑制警告注解

    @SuppressWarning 抑制警告注解 Java.lang.SuppressWarnings 是 J2SE5.0中标准的Annotation 之一. 可以标注在类,字段,方法,参数,构造方法, ...

  10. Uva1553 Caves and Tunnels LCT

    简单题,主要为了练手. #include <cstdio> #include <iostream> #define maxn 100010 using namespace st ...