Spring+quartz 實現定時任務
- 確保jar包已經載入
本文使用maven方式載入相關jar包,pom.xml檔案中配置項如下:
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.2.1</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.2.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>4.2.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.2.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>4.2.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>4.2.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.2.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.2.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.2.1</version>
</dependency>
- 在web.xml檔案中配置上下文
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-core.xml
,
classpath:spring-hibernate.xml
,
classpath:spring-quartz.xml
</param-value>
</context-param>
- 在spring-quartz.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" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="attRecord" class="com.ytang.docinf.tool.Task" />
<bean id="jobtaskAttRecord"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<!-- 呼叫的類 -->
<property name="targetObject">
<ref bean="attRecord" />
</property>
<!-- 呼叫類中的方法 -->
<property name="targetMethod">
<value>test</value>
</property>
</bean>
<bean id="doTimeAttRecord" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<!-- see the example of method invoking job above -->
<property name="jobDetail" ref="jobtaskAttRecord" />
<property name="cronExpression">
<!--每隔五秒執行一次 -->
<value>0/5 * * * * ?</value>
</property>
</bean>
<bean id="startQuartz" lazy-init="false" autowire="no"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="doTimeAttRecord" />
</list>
</property>
</bean>
</beans>
- 在class類中,實現定時任務方法
package com.ytang.docinf.tool;
/*執行定時任務
* kevin
* 2017-04-18*/
public class Task{
public void test(){
System.out.println("定時任務測試");
}
}
相關文章
- Spring+quartz實現動態化定時任務 (轉)Springquartz
- 一看便知spring+quartz定時任務Springquartz
- 定時任務的實現
- Java如何實現定時任務?Java
- 基於redis實現定時任務Redis
- Quartz實現動態定時任務quartz
- PHP定時執行任務的實現PHP
- [筆記]laravel定時任務的實現筆記Laravel
- linux實現一個定時任務Linux
- Linux中如何實現定時任務Linux
- SpringBoot如何實現定時任務Spring Boot
- 【Awen】asp.net定時任務實現ASP.NET
- Java定時任務實現優惠碼Java
- 使用Java實現定時任務排程Java
- Laravel5.6 使用定時任務實現定時發郵件Laravel
- Laravel5.6使用定時任務實現定時發郵件Laravel
- Laravel + Workerman 實現多程式定時器任務Laravel定時器
- java springboot 實現定時器任務JavaSpring Boot定時器
- java定時任務實現的幾種方式Java
- Java實現定時任務的三種方法Java
- oracle job使用方法--實現定時任務Oracle
- 定時任務
- [奇思異想]使用RabbitMQ實現定時任務MQ
- Grails整合Quartz外掛實現定時任務(Job)AIquartz
- Spring 整合 Quartz 實現動態定時任務Springquartz
- Python實現定時任務的多種方式Python
- SpringBoot中併發定時任務的實現、動態定時任務的實現(看這一篇就夠了)Spring Boot
- C#通過rabbitmq實現定時任務(延時佇列)C#MQ佇列
- 直播系統原始碼,實現倒數計時,定時任務原始碼
- Spring Boot 實現定時任務的 4 種方式Spring Boot
- springboot整合quarzt實現動態定時任務Spring Boot
- Spring Boot系列之使用@Scheduled實現定時任務Spring Boot
- 使用者自定義定時任務的php實現PHP
- 初識spring與quartz整合實現定時任務Springquartz
- Node.js 中使用 Redis 來實現定時任務Node.jsRedis
- 定時任務scheduler
- At 、Crontabl定時任務
- crontab定時任務