pom引入

<dependency>

<groupId>org.quartz-scheduler</groupId>

<artifactId>quartz</artifactId>

<version>1.8.6</version>

</dependency>

配置文件xml中引入

<!--配置schedule  -->

<import resource="classpath:context/schedule/schedule-center.xml" />

<!--例子  -->

<import resource="classpath:context/schedule/schedule-syncTeamName-config.xml"/>

<!--配置properties文件 -->

<import resource="classpath:context/envPropertyLoader.xml" />

schedule-center.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:jee="http://www.springframework.org/schema/jee"

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-2.5.xsd

http://www.springframework.org/schema/tx

http://www.springframework.org/schema/tx/spring-tx-2.5.xsd

http://www.springframework.org/schema/jee

http://www.springframework.org/schema/jee/spring-jee-2.5.xsd

http://www.springframework.org/schema/aop

http://www.springframework.org/schema/aop/spring-aop-2.5.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context-2.5.xsd"

default-lazy-init="false">

<!-- 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序 -->

<bean id="schedulerFactory" lazy-init="false" autowire="no"

class="org.springframework.scheduling.quartz.SchedulerFactoryBean">

<property name="triggers">

<list>

<ref bean="tp-schedule.syncTeamNameTrigger" />

</list>

</property>

</bean>

</beans>

envPropertyLoader.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"

"http://www.springframework.org/dtd/spring-beans.dtd">

<beans>

<bean id="configBean" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

<property name="locations">

<list>

<value>classpath:/properties/tp-schedule.properties</value>

</list>

</property>

</bean>

</beans>

schedule-syncTeamName-config.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:jee="http://www.springframework.org/schema/jee"

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-2.5.xsd

http://www.springframework.org/schema/tx

http://www.springframework.org/schema/tx/spring-tx-2.5.xsd

http://www.springframework.org/schema/jee

http://www.springframework.org/schema/jee/spring-jee-2.5.xsd

http://www.springframework.org/schema/aop

http://www.springframework.org/schema/aop/spring-aop-2.5.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context-2.5.xsd"

default-lazy-init="false">

<!-- 定义触发时间 -->

<bean id="tp-schedule.syncTeamNameTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">

<property name="jobDetail">

<ref bean="syncTeamNameJob" />

</property>

<!-- cron表达式 -->

<property name="cronExpression">

<value>${tp-schedule.SYNCTEAMNAMEJOB}</value>

<!--properties文件  tp-schedule.SYNCTEAMNAMEJOB= 0 0 15 ? * FRI  -->

</property>

</bean>

<!-- 定义调用对象和调用对象的方法 -->

<bean id="syncTeamNameJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean" >

<!-- 调用的类 -->

<property name="targetObject">

<ref bean="syncTeamNameJobExecutor" />

</property>

<!-- 调用类中的方法 -->

<property name="targetMethod">

<value>execute</value>

</property>

</bean>

<!-- 入口程序  init-method="execute" 容器启动自动执行一次-->

<bean id="syncTeamNameJobExecutor" class="com.bill99.qamp.schedule.syncTeamNameJobExecutor" init-method="execute">

<property name="iBdf2DeptServiceImpl" ref="iBdf2DeptServiceImpl" />

</bean>

</beans>

syncTeamNameJobExecutor

public class syncTeamNameJobExecutor {

private Logger logger = Logger.getLogger(this.getClass());

private IBdf2DeptService iBdf2DeptServiceImpl;

public void execute(){

logger.info("**-----开始同步TeamName");

iBdf2DeptServiceImpl.insertbdf2dept();

logger.info("**-----同步TeamName完成");

}

public void setiBdf2DeptServiceImpl(IBdf2DeptService iBdf2DeptServiceImpl) {

this.iBdf2DeptServiceImpl = iBdf2DeptServiceImpl;

}

}

定时任务quartz的更多相关文章

  1. spring学习总结(mybatis,事务,测试JUnit4,日志log4j&slf4j,定时任务quartz&spring-task,jetty,Restful-jersey等)

    在实战中学习,模仿博客园的部分功能.包括用户的注册,登陆:发表新随笔,阅读随笔:发表评论,以及定时任务等.Entity层设计3张表,分别为user表(用户),essay表(随笔)以及comment表( ...

  2. spring多个定时任务quartz配置

    spring多个定时任务quartz配置 <?xml version=”1.0″ encoding=”UTF-8″?> <beans xmlns=”http://www.spring ...

  3. Java生鲜电商平台-定时器,定时任务quartz的设计与架构

    Java生鲜电商平台-定时器,定时任务quartz的设计与架构 说明:任何业务有时候需要系统在某个定点的时刻执行某些任务,比如:凌晨2点统计昨天的报表,早上6点抽取用户下单的佣金. 对于Java开源生 ...

  4. 集群服务器+定时任务(Quartz) 重复执行的问题

    x StackExchange.Redis private readonly IDatabase _db; string key = string.Concat("{自己命名的Redis前缀 ...

  5. spring -boot定时任务 quartz 基于 MethodInvokingJobDetailFactoryBean 实现

    spring 定时任务 quartz 基于  MethodInvokingJobDetailFactoryBean 实现 依赖包 如下 <dependencies> <depende ...

  6. (4) Spring中定时任务Quartz集群配置学习

    原 来配置的Quartz是通过spring配置文件生效的,发现在非集群式的服务器上运行良好,但是将工程部署到水平集群服务器上去后改定时功能不能正常运 行,没有任何错误日志,于是从jar包.JDK版本. ...

  7. Spring框架下的定时任务quartz框架的使用

    手头的这个项目需要用到定时任务,但之前没接触过这东西,所以不太会用,从网上找资料,大致了解了一下,其实也不难.Java的定时任务实现有三种,一种是使用JDK自带的Timer那个类来实现,另一种是使用q ...

  8. Spring Scheduler定时任务 + Quartz

    原文地址: https://blog.csdn.net/revitalizing/article/details/61420556 版权声明:本文为博主原创文章,未经博主允许不得转载. https:/ ...

  9. 定时任务quartz与spring的集成

    我想要在spring的集成框架中使用spring , 暂时采用quartz 根据下面的几篇博客实现了(懒得说了,直接丢链接): Quartz实现动态定时任务 Spring 3整合Quartz 2实现定 ...

  10. 动态添加定时任务-quartz定时器

    Quartz动态添加.修改和删除定时任务 在项目中有一个需求,需要灵活配置调度任务时间,刚开始用的Java自带的java.util.Timer类,通过调度一个java.util.TimerTask任务 ...

随机推荐

  1. [Linux]经典面试题 - 系统管理 - 备份策略

    [Linux]经典面试题 - 系统管理 - 备份策略 目录 [Linux]经典面试题 - 系统管理 - 备份策略 一.备份目录 1.1 系统目录 1.2 服务目录 二.备份策略 2.1 完整备份 2. ...

  2. 复习Spring第二课--AOP原理及其实现方式

    AOP原理: AOP,面向方面的编程,使用AOP,你可以将处理方面(Aspect)的代码注入主程序,通常主程序的主要目的并不在于处理这些aspect.AOP可以防止代码混乱.AOP的应用范围包括:持久 ...

  3. linux 下安装 docker 环境

    一分钟了解 Docker Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从Apache2.0协议开源.Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级.可移植的容器中,然 ...

  4. Java核心API-日期时间

    java.util.Date Date类用来表示时间点. 时间是用距离一个固定时间点的毫秒数表示的,这个时间点就是纪元. UTC时间是为表示这个纪元的科学标准时间,从1970年1月1日0时开始.另一种 ...

  5. git schnnel failed to receive handshake, SSLTLS connection failed

    git schnnel failed to receive handshake, SSLTLS connection failed 报错,查看原因为git安装时ssl选择的不是openssl.重新安装 ...

  6. 乘风破浪,.Net Core遇见Dapr,为云原生而生的分布式应用运行时

    Dapr是一个由微软主导的云原生开源项目,国内云计算巨头阿里云也积极参与其中,2019年10月首次发布,到今年2月正式发布V1.0版本.在不到一年半的时间内,github star数达到了1.2万,超 ...

  7. 1.QT多线程使用小结

    开头 一个进程可以有一个或更多线程同时运行.线程可以看做是"轻量级进程",进程完全由操作系统管理,线程即可以由操作系统管理,也可以由应用程序管理. Qt 使用QThread来管理线 ...

  8. 22.17、heartbeat和drbd整合

    1.要确保master-db和slave-db的drbd服务和heartbeat服务都已经停止了: 2.heartbeate设置: 修改master-db和slave-db的'/etc/ha.d/ha ...

  9. 资源:Git快速下载路径

    Git快速下载地址: 地址:https://npm.taobao.org/mirrors/git-for-windows/

  10. Java:Java中static关键字作用

    static关键字最基本的用法是: 1.被static修饰的变量属于类变量,可以通过类名.变量名直接引用,而不需要new出一个类来 2.被static修饰的方法属于类方法,可以通过类名.方法名直接引用 ...