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里面 ...
随机推荐
- 2016暑假多校联合---A Simple Chess
2016暑假多校联合---A Simple Chess Problem Description There is a n×m board, a chess want to go to the po ...
- [PHP] 使用Socket提供Http服务
我的SimpleLoader里面的一块 https://github.com/taoshihan1991/simpleloader <?php namespace Server; class S ...
- 2005年IT行业趋势Top10
未来三年内对组织有潜在的重大影响IT趋势.这里的IT趋势的摘要: 1. 计算位于任何地方 智能手机,平板,电视盒,可穿戴设备,可连接的屏幕,对于适应移动用户所求要的整体环境的需求在不断增强.这会继续提 ...
- Loadrunner中web_find和web_reg_find函数的使用与区别
总结一下Loadrunner中的检查点函数,主要介绍两个函数:web_find()和web_reg_find():这两个函数均用于内容的查找,但两者也有本质的区别,具体介绍如下:一.web_find( ...
- GJM : 安装SqlServer遇到问题的解决方案 [原创]
感谢您的阅读.喜欢的.有用的就请大哥大嫂们高抬贵手"推荐一下"吧!你的精神支持是博主强大的写作动力以及转载收藏动力.欢迎转载! 版权声明:本文原创发表于 [请点击连接前往] ,未经 ...
- GJM:C# WinForm开发系列 - DataGridView 使用方法集锦 [转载]
1.DataGridView实现课程表 testcontrol.rar 2.DataGridView二维表头及单元格合并 DataGridView单元格合并和二维表头.rar myMultiColHe ...
- Method Draw – 很好用的 SVG 在线编辑器
Method Draw 是一款在线 SVG 编辑器,是 SVG Edit 的一个分支.Method Draw 的目的是改进 SVG Edit 的可用性和用户体验.它移除了 line-caps/corn ...
- [deviceone开发]-do_SlideListView的简单示例
一.简介 利用提供的SlideListVIew实现那种cell可以滑动露出底部按钮的功能 主要组件:do_slidelistview 二.效果图 三.相关讨论 http://bbs.deviceone ...
- 汉王云名片识别(SM)组件开发详解
大家好,最近在DeviceOne平台上做了一个汉王云名片识别的功能组件.下面把我开发过程给大家做一个分享,希望可以帮助到大家. 下面我把我的思路给大家讲解一下. 1.找到我要集成的sdk,也就是汉 ...
- flume 集群安装
./pssh -h ./host/all.txt -P mkdir /usr/local/app ./pssh -h ./host/all.txt -P tar zxf /usr/local/soft ...