此文章是基于  搭建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. 使用maven创建Archetype

    Archetype原型 也就是说为项目生成一个原型,可以把这个项目发布,其他人就可以直接通过命令构建一个原型项目了. 其实我一开始也是不知道maven还有这个功能的,但是在使用的springside的 ...

  2. Razor语法大全

    本文页面来源地址:http://www.cnblogs.com/dengxinglin/p/3352078.html Razor是基于framewor4以上写的一个开源项目:https://githu ...

  3. GitHub for windows 使用方法

    1. ①http://windows.github.com/ 下载GitHub for Windows,大约660K,一个在线安装程序,如图: ②.运行GitHubSetup.exe,如下图,可能会下 ...

  4. 修改windows系统文件权限

    修改windows系统文件总是提示没有权限,虽然已是administrator也不管用. 以下方法可以解决: 右键属性,安全,高级,所有者,编辑,选择当前用户并确定, 回到上一页再确定, 然后在安全页 ...

  5. Asynchronous Jobs

    Because Play is a web application framework, most of the application logic is done by controllers re ...

  6. letter-spacing

    letter-spacing:3px的意思就是字母之间的间距是3px:

  7. 8款适合乐队、歌手和音乐家免费 WordPress 主题

    这篇文章与大家分享8款适合乐队.歌手和音乐家免费 WordPress WordPress 音乐网站主题.WordPress 作为最流行的博客系统,插件众多,易于扩充功能.安装和使用都非常方便,而且有许 ...

  8. 使用ruby搭建简易的http服务和sass环境

    使用ruby搭建简易的http服务和sass环境 由于在通常的前端开发情况下,我们会有可能需要一个http服务,当然你可以选择自己写一个node的http服务,也比较简单,比如下面的node代码: v ...

  9. Android Animation学习(一) Property Animation原理介绍和API简介

    Android Animation学习(一) Property Animation介绍 Android Animation Android framework提供了两种动画系统: property a ...

  10. 好推二维码如何通过应用宝微下载支持微信自动打开APP下载?

    好推二维码 官网 http://www.hotapp.cn 1. 为什么使用应用宝微下载? APP下载二维码,通过微信扫描下载的时候,微信目前只支持应用宝微下载,才能在微信里直接打开下载,否则就需要在 ...