首先,新建一个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. 快充 IC BQ25896 如何判斷 手機插著 adapter 充電器時,adapter Iout 大於限制,adapter Vout 小於 限制,導致 battery 不但沒充電且還需放電。

    若電池在 放電時,ICHGR 為0. 若電池在 充電時,ICHGR有變化.   下面有寫到 charge current 所以不是 discharge current   狀況:           ...

  2. chroot下二进制程序迁移

    #!/bin/bash # #define function#Copy binary programcp_bin(){ cmd_dir=${cmd_path%/*} [ ! -d /mnt/sysro ...

  3. AC日记——[USACO15DEC]最大流Max Flow 洛谷 P3128

    题目描述 Farmer John has installed a new system of  pipes to transport milk between the  stalls in his b ...

  4. Java调用Python程序

    最近,需要在应用中,需要使用Java程序去调用Python代码,主要有两种实现方式. 一.使用Jython架包 因为调用的Python代码中需要使用Json对象,开始使用jython2.5.2,发现不 ...

  5. OpenLayers3 动画

    参考文章 openlayers3中三种动画实现

  6. eclipse项目java版本更改

    然后.右键点击项目->properties->Java Compiler->....如图 ​ 最后,右键点击项目->properties->Project  Facets ...

  7. fastscript增加三方控件之二

    fastscript增加三方控件之二 unit fs_BsDataSet; interface {$i fs.inc} uses SysUtils, Classes, fs_iinterpreter, ...

  8. python pyqtgraph 保存图片到本地

    pyqtgraph官方给的示例居然会报错2333 官方文档传送门:#####pyqtgraph export pyqtgraph支持在可视化窗口中右键保存(Exporting from the GUI ...

  9. Windows10系统修复

    sfc /scannow 命令将扫描所有受保护的系统文件,并用位于 %WinDir%\System32\dllcache 的压缩文件夹中的缓存副本替换损坏的文件. %WinDir% 占位符代表Wind ...

  10. 转:mybatis——select、insert、update、delete

    一.select <!-- 查询学生,根据id --> <select id="getStudent" parameterType="String&qu ...