spring定时器(一)
此文章是基于 搭建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定时器(一)的更多相关文章
- spring定时器,定时器一次执行两次的问题
Spring 定时器 方法一:注解形式 配置文件头加上如下: xmlns:task="http://www.springframework.org/schema/task" htt ...
- Spring 定时器Quartz的用法
Spring定时器Quartz的用法也很简单,需要引入quartz-all-1.5.2.jar java代码如下: package com.coalmine.desktop; import java. ...
- spring定时器,当遇见半小时的情况时
spring定时器遇见半小时的解决方法(这里只提供注解方式) @Scheduled(fixedRate=6000000)//每隔100分钟执行方法 fixedRate的值是毫秒
- Spring 定时器的使用
spring定时器应用 相关类: org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean 配置定时远行方法 o ...
- spring定时器
本人小菜鸟一枚,今天在公司看到一段spring定时器配置,自己总结一下! <!-- 定义调用对象和调用对象的方法 --><bean id="jobtask9" c ...
- 两种流行Spring定时器配置:Java的Timer类和OpenSymphony的Quartz
1.Java Timer定时 首先继承java.util.TimerTask类实现run方法 import java.util.TimerTask; public class EmailReportT ...
- 注解式开发spring定时器
1:spring 配置文件中增加这句 <task:annotation-driven/> 2:确保扫描程序能够扫描后 下面第3步骤的java类 <context:co ...
- spring定时器设置(转自:http://my.oschina.net/LvSantorini/blog/520049)
转自:http://my.oschina.net/LvSantorini/blog/520049<!-- MessageRequestTask类中包含了msgRequest方法,用于执行定时任务 ...
- spring定时器,5步完成
spring定时器,5步完成,我们开发的时候会用定时执行任务. 用spring框架时,可以直接使用spring定时功能 1.创建任务调度类,里面一个方法,方法名为work 2. spring配置文件, ...
- spring定时器用Annotation兑现
spring定时器用Annotation实现 0人收藏此文章, 我要收藏发表于3个月前 , 已有46次阅读 共0个评论 1.ApplicationContext.xml配置 a).需要在xmlns里面 ...
随机推荐
- 自学H5第一天笔记
1.web前端开发工程师 1.web前端开发工程师是做什么的 要与网站打交道 2.成为一名web前端开发工程师需要具备的条件 1.兴趣 2.敲代码 3.web前端开发需要学习什么 1.软件 浏览器:有 ...
- [javaSE] 反射-方法的反射
1.如何获取某个方法 方法的名称和方法的参数列表才能唯一决定一个方法 2.方法反射的操作 method.invoke(); package com.tsh.reflect; import java.l ...
- MyEclipse常用插件使用教程
一.Findbugs 1. 配置 1.1 打开FindBugs视图: Windows => Show View => Other… => FindBugs => Bug Inf ...
- 通过Google身份验证器加强Linux帐户安全
下载Google的身份验证模块: # wget https://google-authenticator.googlecode.com/files/libpam-google-authenticato ...
- Space.js – HTML 驱动的页面 3D 滚动效果
为了让我们的信息能够有效地沟通,我们需要创建用户和我们的媒体之间的强有力的联系.今天我们就来探讨在网络上呈现故事的新方法,并为此创造了一个开源和免费使用的 JavaScript 库称为 space.j ...
- 【特别推荐】几款极好的 JavaScript 下拉列表插件
表单元素让人爱恨交加.作为网页最重要的组成部分,表单几乎无处不在,从简单的邮件订阅.登陆注册到复杂的需要多页填写的信息提交功能,表单都让开发者花费了大量的时间和精力去处理,以期实现好用又漂亮的表单功能 ...
- 从0开始学angularjs-笔记02
上一节课主要跟大家讲解了angularjs的几种特性和看了一个简单的双向绑定的例子.最近都没有时间写博客了....忙成狗呀...今天周末,在写一篇吧~~ 今天主要跟大家详细讲解一下angularjs的 ...
- 高性能的JavaScript库---Lodash
上周在仿做Nodejs社区的时候,遇到了lodash这个javascript库,很惭愧,那也是我第一次听说lodash.人嘛,对于新鲜的事物总是会或多或少感到些好奇的,于是就毫不犹豫地去lodash官 ...
- linux下发布的执行文件崩溃的问题定位 心得一则
C++ Release版本发布到客户处执行时,如果程序崩溃,有什么办法能够快速的确认程序的问题呢? 如果能gdb调试的话,比较简单了,可以使用gdb命令,类似如下: gdb ##set args ** ...
- JavaScript学习04 对象
JavaScript学习04 对象 默认对象 日期对象Date, 格式:日期对象名称=new Date([日期参数]) 日期参数: 1.省略(最常用): 2.英文-数值格式:月 日,公元年 [时:分: ...