首先,新建一个java项目,下面导入需要的jar包:

这里有你需要的jar包哦。

jar包下载

在src文件夹下,新建一个applicationContext.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util" xmlns:tx="http://www.springframework.org/schema/tx"
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-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd"> <!-- Spring 定时器演示 --> <!-- 定时器开关 -->
<task:annotation-driven /> <bean id="LogTask" class="com.test.Test"></bean> <task:scheduled-tasks>
<!-- 这里表示的是2s执行一次 -->
<task:scheduled ref="LogTask" method="execute" cron="*/2 * * * * ?" />
</task:scheduled-tasks> </beans>

在web.xml中配置:

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

创建定时启动的java类:

test.java

package com.test;

public class Test {
public void execute() {
System.out.println("定时器启动了。。。");
}
}

部署在Tomcat中启动Tomcat即可。

具体定时器执行的时间可以再行研究。

此demo亲测好使。。。。。

spring定时器的配置的更多相关文章

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

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

  2. Spring定时器注解配置

    spring-task.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=&qu ...

  3. Spring定时器XML配置

    spring-task.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=&qu ...

  4. spring 定时器时间配置

    Spring--quartz中cronExpression The '*' character is used to specify all values. For example, "*& ...

  5. spring定时器设置(转自:http://my.oschina.net/LvSantorini/blog/520049)

    转自:http://my.oschina.net/LvSantorini/blog/520049<!-- MessageRequestTask类中包含了msgRequest方法,用于执行定时任务 ...

  6. 两种流行Spring定时器配置:Java的Timer类和OpenSymphony的Quartz

    1.Java Timer定时 首先继承java.util.TimerTask类实现run方法 import java.util.TimerTask; public class EmailReportT ...

  7. spring task定时器的配置使用

    spring task的配置方式有两种:配置文件配置和注解配置. 1.配置文件配置 在applicationContext.xml中增加spring task的命名空间: xmlns:task=&qu ...

  8. spring定时器,定时器一次执行两次的问题

    Spring 定时器 方法一:注解形式 配置文件头加上如下: xmlns:task="http://www.springframework.org/schema/task" htt ...

  9. Spring 定时器Quartz的用法

    Spring定时器Quartz的用法也很简单,需要引入quartz-all-1.5.2.jar java代码如下: package com.coalmine.desktop; import java. ...

随机推荐

  1. java三种匿名的方式开启线程

    package demo04; /* * 使用匿名内部类,实现多线程程序 * 前提:继承或者接口实现 * new 父类或者接口(){ * 重写 抽象方法 * } */ public class Thr ...

  2. (39)C#Ping类

    一.Ping类 引用命名空间 using System.Net.NetworkInformation 控制台版 using System; using System.Collections.Gener ...

  3. Codeforces Gym 100203G Good elements 暴力乱搞

    原题链接:http://codeforces.com/gym/100203/attachments/download/1702/statements.pdf 题解 考虑暴力的复杂度是O(n^3),所以 ...

  4. Delphi图像处理 -- 颜色矩阵变换

    转载自阿发伯:http://blog.csdn.net/maozefa/article/details/8316430 阅读提示:     <Delphi图像处理>系列以效率为侧重点,一般 ...

  5. POJ 1017 Packets(积累)

    [题意简述]:这个是别人的博客,有清晰的题意描写叙述.和解题思路,借助他的想法,能够非常好的解决问题! [分析]:贪心?模拟?见代码 //216K 16Ms #include<iostream& ...

  6. intent 支持的action 动作

    String ACTION_AIRPLANE_MODE_CHANGED Broadcast Action: The user has switched the phone into or out of ...

  7. phonegap工程搭建基础(一)

      官网:http://cordova.apache.org   一.环境配置 1. 安装Cordova   on OS X and Linux: $ sudo npm install -g cord ...

  8. JS推断浏览器类型与版本号

    在JS中推断浏览器的类型,预计是每一个编辑过页面的开发者都遇到过的问题.在众多的浏览器产品中.IE.Firefox.Opera.Safari........众多品牌却标准不一,因此时常须要依据不同的浏 ...

  9. 百度 BAE 项目部署

    转载:http://www.cnblogs.com/shamoyuu/p/node_bae.html 百度有一个应用引擎,价格非常便宜,Java的tomcat每天4毛钱,node每天2毛钱,我以前在上 ...

  10. Cocos2d-X中的粒子

    Cocos2d-x引擎提供了强大的type=cocos2d-x&url=/doc/cocos-docs-master/manual/framework/native/v3/particle-s ...