此文章是基于  搭建Jquery+SpringMVC+Spring+Hibernate+MySQL平台

一. jar包介绍

  1. spring-framework-4.3.4.RELEASE 的 libs 文件夹下得到:

spring-context-support-4.3.4.RELEASE.jar

  2. quartz-2.2.3.jar

二. 相关文件介绍

  1. applicationInfrastructure.xml,定时器配置文件

    spring的bean类无法在定时器中自动注入,需要在配置中手动添加 。<property name="jobDataAsMap">

<?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:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-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/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"> <!-- 定义定时器任务 -->
<bean id="fixTimeJob"
class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<!-- 指定任务对应的类 -->
<property name="jobClass" value="com.ims.infrastructure.quartz.FixTimeJob" />
<!-- 往任务中注入bean -->
<property name="jobDataAsMap">
<map> </map>
</property>
</bean> <!-- 定义任务的触发器 -->
<bean id="fixTimeJobTrigger"
class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean">
<property name="jobDetail" ref="fixTimeJob" />
<!-- 重复执行间隔时间(毫秒) -->
<property name="repeatInterval" value="30000"/>
<!-- 服务启动后多久执行(毫秒) -->
<property name="startDelay" value="1000"/>
</bean> <!-- 需要被执行的触发器集合 -->
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="fixTimeJobTrigger"/>
</list>
</property>
</bean> </beans>

  2. FixTimeJob.java,定时器任务类

package com.ims.infrastructure.quartz;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean; public class FixTimeJob extends QuartzJobBean{ @Override
protected void executeInternal(JobExecutionContext arg0)
throws JobExecutionException {
System.out.println("hello!");
} }

三. 测试
  启动服务,按照定时器配置文件设置的时间间隔,在后台每30秒输出"hello!"

spring定时器(一)的更多相关文章

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

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

  2. Spring 定时器Quartz的用法

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

  3. spring定时器,当遇见半小时的情况时

    spring定时器遇见半小时的解决方法(这里只提供注解方式) @Scheduled(fixedRate=6000000)//每隔100分钟执行方法 fixedRate的值是毫秒

  4. Spring 定时器的使用

    spring定时器应用 相关类: org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean 配置定时远行方法 o ...

  5. spring定时器

    本人小菜鸟一枚,今天在公司看到一段spring定时器配置,自己总结一下! <!-- 定义调用对象和调用对象的方法 --><bean id="jobtask9" c ...

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

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

  7. 注解式开发spring定时器

    1:spring 配置文件中增加这句    <task:annotation-driven/>  2:确保扫描程序能够扫描后  下面第3步骤的java类    <context:co ...

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

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

  9. spring定时器,5步完成

    spring定时器,5步完成,我们开发的时候会用定时执行任务. 用spring框架时,可以直接使用spring定时功能 1.创建任务调度类,里面一个方法,方法名为work 2. spring配置文件, ...

  10. spring定时器用Annotation兑现

    spring定时器用Annotation实现 0人收藏此文章, 我要收藏发表于3个月前 , 已有46次阅读 共0个评论 1.ApplicationContext.xml配置 a).需要在xmlns里面 ...

随机推荐

  1. Extjs 窗体居中,双重窗体弹出时清除父窗体的鼠标事件

    这个是监控窗体缩放的事件 缩放中居中主要在 'beforeshow' 和 'destroy'两个事件里面监控 var EditTempWindow; Ext.EventManager.onWindow ...

  2. 编译安装php-amq扩展

    用途:这个扩展是用来操作rabbitmq服务端的 一.安装总括 1.编译安装librabbitmq库 这是一个开源c语言的库.用来与rabbitmq进行通信 而php的php-amqp扩展就是使用这个 ...

  3. [javascript] 对象拷贝

    Object.prototype.clone = function() { var copy = (this instanceof Array) ? [] : {}; for (attr in thi ...

  4. 在selenium2.0中使用selenium1.0的API

    Selenium2.0中使用WeDriver API对页面进行操作,它最大的优点是不需要安装一个selenium server就可以运行,但是对页面进行操作不如selenium1.0的Selenium ...

  5. 高效 Java Web 开发框架 JessMA v3.3.1 正式发布

    JessMA(原名:Portal-Basic)是一套功能完备的高性能 Full-Stack Web 应用开发框架,内置可扩展的 MVC Web 基础架构和 DAO 数据库访问组件(内部已提供了 Hib ...

  6. BeforeProperties/AfterProperties in Event Receivers

    Sharepoint List List BeforeProperties AfterProperties properties.ListItem ItemAdding No Value No Val ...

  7. TwentyTwenty – 使用 jQuery 实现图片对比功能

    这是一款非常棒的图片对比工具,能够方便的应用到你的网站中.其基本思路是把两张图片层叠在一起,当你拖动滑竿的时候,利用 CSS clip 裁剪图片,进行形成视觉对比效果. 您可能感兴趣的相关文章 Met ...

  8. 提高CSS文件可维护性的五种方法

    当完成一项前端的工作之后,许多人都会忘记该项目的结构与细节.然而代码并不是马上就能完全定型,在余下的时间里还有不断的维护工作,而这些工作也许不会是你自己完成.所以,结构优良的代码能很大程度上优化它的可 ...

  9. Html技巧 语义化你的代码

    首先是关于语义(Semantics)和默认样式的区别,默认样式是浏览器设定的一些常用tag的表现形式,语义化的主要目的就是让大家直观的认识标签(markup)和属性(attribute)的用途和作用. ...

  10. umeng 渠道统计 android

    1.配置AndroidManifest.xml,添加权限 <uses-permission android:name="android.permission.ACCESS_NETWOR ...