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;

}

}

最新文章

  1. 用VS Code写Python程序
  2. 项目自动化建构工具gradle 入门3——生一个exe的helloWorld
  3. 微信小程序 - 开发指南
  4. 关于seajs模块化的搭建
  5. wc命令
  6. OB函数
  7. pthread_attr_setdetachstate
  8. guacamole 0.8.3 项目部署 桌面虚拟化
  9. [ASE][Daily Scrum]11.19
  10. Eclipse:Cannot complete the install because of a conflicting dependency.问题解决
  11. jQuery 写的幻灯左右切换插件
  12. UVa 11426 (欧拉函数 GCD之和) GCD - Extreme (II)
  13. java 删除字符串中的特定字符
  14. ACM入门:第s名的小红
  15. windows 注入 之 CreateRemoteThread
  16. JavaScript中错误正确处理方式,你用对了吗?
  17. C/C++ 数据结构之算法
  18. linux svn客户端安装
  19. JS性能优化 之 FOR循环
  20. apache两种工作模式详解

热门文章

  1. leetcode5697. 检查二进制字符串字段
  2. Linux驱动中的EPROBE_DEFER是个啥
  3. redis淘汰+过期双向保证高可用 | redis 为什么那么快?
  4. ClickHouse学习系列之七【系统命令介绍】
  5. JS里的异步实例化
  6. 没有指定非静态方法,Unity与Android通信错误
  7. .net core 支付宝,微信支付 三
  8. Linux-ansible批量管理
  9. IDEA打开文件时,关闭SonarLint自动扫描
  10. vsftpd配置文件详解(转)