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的更多相关文章

  1. 最新 Spring 4.2.2 集成 Quartz Scheduler 2.2.2 任务调度示例

    参考http://blog.csdn.net/defonds/article/details/49496895 本文将演示如何通过 Spring 使用 Quartz Scheduler 进行任务调度. ...

  2. spring集成quartz scheduler

    创建项目 有两种创建quart配置作业 1.使用MethodInvokingJobDetailFactoryBean  Quartz Scheduler 配置作业(MethodInvokingJobD ...

  3. Table of Contents - Quartz Scheduler

    Getting Started Hello World Integration with Spring Quartz Scheduler Developer Guide Usage of JobDat ...

  4. quartz集群分布式(并发)部署解决方案-Spring

    项目中使用分布式并发部署定时任务,多台跨JVM,按照常理逻辑每个JVM的定时任务会各自运行,这样就会存在问题,多台分布式JVM机器的应用服务同时干活,一个是加重服务负担,另外一个是存在严重的逻辑问题, ...

  5. Quartz Scheduler(2.2.1) - hello world

    简单示例 1. maven 依赖 <dependencies> <dependency> <groupId>org.quartz-scheduler</gro ...

  6. 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 ...

  7. Quartz Scheduler 开发指南(1)

    Quartz Scheduler 开发指南(1) 原文地址:http://www.quartz-scheduler.org/generated/2.2.2/html/qtz-all/ 实例化调度程序( ...

  8. 整合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 ...

  9. Sentinel Getting Started And Integration of Spring Cloud Alibaba Tutorials

    原文链接:Sentinel Getting Started And Integration of Spring Cloud Alibaba Tutorials Sentinel Getting Sta ...

随机推荐

  1. [一]Head First设计模式之【策略模式】(鸭子设计的优化历程)

    public abstract class Duck { FlyBehavior flyBehavior; QuackBehavior quackBehavior; public Duck() { } ...

  2. CodeForces 732D Exams (二分)

    题意:某人要考试,有n天考m个科目,然后有m个科目要考试的时间和要复习多少天才能做,问你他最早考完所有科目是什么时间. 析:二分答案,然后在判断时,直接就是倒着判,很明显后出来的优先,也就是一个栈. ...

  3. 虚拟机VMware里 windows server 2003 扩充C盘方法

    你会经常用windows server 2003 吗?应该不会吧,有时一些东西必须装在windows server 2003 上才能用,所以 用虚拟机把,好,装在虚拟机上,8G的C盘够你用吗,一个稍微 ...

  4. Thinkphp框架 -- ajax无刷新上传图片

    用Thinkphp框架做无刷新上传图片 视图层 View <!doctype html> <html lang="en"> <head> < ...

  5. 让table 居于页面的正中间(上下左右均居中的方法)

    ? <table bgcolor="#jnkc" width="300" height="200" style="posit ...

  6. 【转】adns解析库——域名解析实例(C++、linux)

    转自:http://blog.csdn.net/fty8788/article/details/7480334 adns是一个开源的dns解析库 官方文档:http://www.chiark.gree ...

  7. [Canvas] Make Canvas Responsive to Pixel Ratio

    Canvas is great for high performance graphics rendering but by default the results look blocky on ph ...

  8. Office 365 Certificate Exam Resources

    70-321 Deploying Office 365 Deploying Office 365 Jump Start (01): Infrastructure Planning Deploying ...

  9. ios开发——实战Swift篇&简单项目的实现

    学了这么久的swift语法和相关技术,今天忍不住手痒痒就写了一个swift的小项目,这个项目非常简单(只是使用一个UITableView),但是里面的功能却非常有用. 我们要实现的功能是这样的: 程序 ...

  10. PHP泛域名应用

    以Windows开发环境 1.windows =>hosts文件 127.0.0.1    asia.t127.0.0.1    *.asia.t127.0.0.1    www.asia.t1 ...