Quartz Scheduler(2.2.1) - Integration with Spring
1. maven 依赖:
<properties>
<spring.version>3.2.3.RELEASE</spring.version>
<quartz.version>2.2.1</quartz.version>
</properties> <dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency> <dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>${quartz.version}</version>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz-jobs</artifactId>
<version>${quartz.version}</version>
</dependency> <dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.6</version>
<scope>provided</scope>
</dependency> <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
</dependency> </dependencies>
2. 定义任务类:
package com.huey.hello.quartz;
import java.util.Date;
import org.quartz.JobExecutionException;
import com.huey.hello.quartz.utils.DateUtils;
public class HelloJob {
public void sayHello() throws JobExecutionException {
System.out.println("hello " + DateUtils.dateToStr(new Date()));
}
}
3. Spring applicationContext.xml 配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <!-- 配置任务实例 -->
<bean id="helloJob" class="com.huey.hello.quartz.HelloJob" /> <!-- 配置 JobDetail -->
<bean id="myJobDetailFactory" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<!-- 指定任务 -->
<property name="targetObject" ref="helloJob" />
<!-- 指定执行的方法 -->
<property name="targetMethod" value="sayHello" />
</bean> <!-- 配置触发器 -->
<bean id="myTriggerFactory" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<!-- 指定 JobDetail -->
<property name="jobDetail" ref="myJobDetailFactory" />
<!-- 指定 cron 表达式 -->
<property name="cronExpression" value="0/5 * * * * ?" />
</bean> <!-- 配置 scheduler 工厂 -->
<bean id="schedulerFactory" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="myTriggerFactory"/>
</list>
</property>
<!-- 是否自动启动 -->
<property name="autoStartup" value="true" />
</bean> </beans>
Quartz Scheduler(2.2.1) - Integration with Spring的更多相关文章
- 最新 Spring 4.2.2 集成 Quartz Scheduler 2.2.2 任务调度示例
参考http://blog.csdn.net/defonds/article/details/49496895 本文将演示如何通过 Spring 使用 Quartz Scheduler 进行任务调度. ...
- spring集成quartz scheduler
创建项目 有两种创建quart配置作业 1.使用MethodInvokingJobDetailFactoryBean Quartz Scheduler 配置作业(MethodInvokingJobD ...
- Table of Contents - Quartz Scheduler
Getting Started Hello World Integration with Spring Quartz Scheduler Developer Guide Usage of JobDat ...
- quartz集群分布式(并发)部署解决方案-Spring
项目中使用分布式并发部署定时任务,多台跨JVM,按照常理逻辑每个JVM的定时任务会各自运行,这样就会存在问题,多台分布式JVM机器的应用服务同时干活,一个是加重服务负担,另外一个是存在严重的逻辑问题, ...
- Quartz Scheduler(2.2.1) - hello world
简单示例 1. maven 依赖 <dependencies> <dependency> <groupId>org.quartz-scheduler</gro ...
- Quartz Scheduler(2.2.1) - Working with JobStores
About Job Stores JobStores are responsible for keeping track of all the work data you give to the sc ...
- Quartz Scheduler 开发指南(1)
Quartz Scheduler 开发指南(1) 原文地址:http://www.quartz-scheduler.org/generated/2.2.2/html/qtz-all/ 实例化调度程序( ...
- 整合shiro出现【Correct the classpath of your application so that it contains a single, compatible version of org.quartz.Scheduler】
跑的时候出现错误: Description: An attempt was made to call the method org.quartz.Scheduler.getListenerManage ...
- Sentinel Getting Started And Integration of Spring Cloud Alibaba Tutorials
原文链接:Sentinel Getting Started And Integration of Spring Cloud Alibaba Tutorials Sentinel Getting Sta ...
随机推荐
- AVCaptureSession 照相时获取 AVCaptureVideoPreviewLayer尺寸
http://stackoverflow.com/questions/14153878/avcapturesession-preset-photo-and-avcapturevideopreviewl ...
- 转:使用memc-nginx和srcache-nginx模块构建高效透明的缓存机制
原文地址:http://blog.codinglabs.org/articles/nginx-memc-and-srcache.html 为了提高性能,几乎所有互联网应用都有缓存机制,其中Memcac ...
- UVA 11134 - Fabled Rooks(贪心+优先队列)
We would like to place n rooks, 1 ≤ n ≤ 5000, on a n×n board subject to the following restrict ...
- my-view-isnt-reflecting-changes-ive-made-to-the-underlying-tables
FROM http://sqlstudies.com/2013/01/20/my-view-isnt-reflecting-changes-ive-made-to-the-underlying-tab ...
- Cts框架解析(12)-ITargetPreparer
測试开启前的设备系统准备工作. 接口 /* * Copyright (C) 2010 The Android Open Source Project * * Licensed under the Ap ...
- [Javascript] Maybe Functor
In normal Javascript, we do undefine check or null check: , name: "Suvi"}; var name = pers ...
- [AngularJS] ui-router: Abstract States
ui-router has the powerful ability to define abstract states, or states that can't be navigated to, ...
- 日志分析(二) logstash patterns
grok-patterns内置了很多基础变量的正则表达式的log解析规则,其中包括apache的log解析(同样可以用于nginx的log解析). 基于nginx日志分析配置: 1.配置nginx ...
- AngularJS - 插件,module注入
Index.html <body> <div ng-app="myApp"> <div ng-controller="firstContro ...
- 最新搭建GIT服务器仓库
新开了一个项目,现在需要将代码放在公司GIT服务器上面.所以这里需要了一些问题..记录一下.因为原来公司这边的服务器的git用户都是创建好的.这里没有创建.需要的可以看看:http://www.cnb ...