package com.pkfare.task.manage.config;

import org.quartz.spi.TriggerFiredBundle;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.SpringBeanJobFactory;
import org.springframework.stereotype.Component; @Configuration
@Component
public class JobBeanJobFactory extends SpringBeanJobFactory implements ApplicationContextAware { private ApplicationContext applicationContext; public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
} @Override
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
Object jobInstance = super.createJobInstance(bundle);
//把Job交给Spring来管理,这样Job就能使用由Spring产生的Bean了
applicationContext.getAutowireCapableBeanFactory().autowireBean(jobInstance);
return jobInstance;
} }
import com.pkfare.task.manage.service.impl.SelectTaskServiceImpl;
import com.pkfare.task.manage.util.ReadConfigUtil;
import com.pkfare.task.manage.job.MainJob;
import org.quartz.JobDetail;
import org.quartz.impl.triggers.CronTriggerImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.quartz.SchedulerFactoryBean; import javax.sql.DataSource;
import java.text.ParseException; import static org.quartz.JobBuilder.newJob; /**
* Created by llq on 2016/10/28.
*/
@Configurable
public class QuartzConfig { @Autowired
private JobBeanJobFactory jobBeanJobFactory; @Autowired
SelectTaskServiceImpl selectTaskService; @Autowired
@Bean
public SchedulerFactoryBean SchedulerFactoryBean(DataSource dataSource) throws ParseException { SchedulerFactoryBean bean = new SchedulerFactoryBean();
bean.setDataSource(dataSource); bean.setQuartzProperties(ReadConfigUtil.readConfig("quartz.properties"));
bean.setSchedulerName("CRMscheduler");
bean.setStartupDelay(3);
bean.setApplicationContextSchedulerContextKey("applicationContextKey");
bean.setOverwriteExistingJobs(true);
bean.setAutoStartup(true);
bean.setJobFactory(jobBeanJobFactory); return bean;
} }

http://www.blogjava.net/paulwong/archive/2014/11/14/420104.html

quarz spring boot的更多相关文章

  1. 国内最全的Spring Boot系列之二

    历史文章 <国内最全的Spring Boot系列之一> 视频&交流平台 SpringBoot视频:http://t.cn/R3QepWG Spring Cloud视频:http:/ ...

  2. 玩转spring boot——快速开始

    开发环境: IED环境:Eclipse JDK版本:1.8 maven版本:3.3.9 一.创建一个spring boot的mcv web应用程序 打开Eclipse,新建Maven项目 选择quic ...

  3. 【微框架】之一:从零开始,轻松搞定SpringCloud微框架系列--开山篇(spring boot 小demo)

    Spring顶级框架有众多,那么接下的篇幅,我将重点讲解SpringCloud微框架的实现 Spring 顶级项目,包含众多,我们重点学习一下,SpringCloud项目以及SpringBoot项目 ...

  4. 玩转spring boot——开篇

    很久没写博客了,而这一转眼就是7年.这段时间并不是我没学习东西,而是园友们的技术提高的非常快,这反而让我不知道该写些什么.我做程序已经有十几年之久了,可以说是彻彻底底的“程序老炮”,至于技术怎么样?我 ...

  5. 玩转spring boot——结合redis

    一.准备工作 下载redis的windows版zip包:https://github.com/MSOpenTech/redis/releases 运行redis-server.exe程序 出现黑色窗口 ...

  6. 玩转spring boot——AOP与表单验证

    AOP在大多数的情况下的应用场景是:日志和验证.至于AOP的理论知识我就不做赘述.而AOP的通知类型有好几种,今天的例子我只选一个有代表意义的“环绕通知”来演示. 一.AOP入门 修改“pom.xml ...

  7. 玩转spring boot——结合JPA入门

    参考官方例子:https://spring.io/guides/gs/accessing-data-jpa/ 接着上篇内容 一.小试牛刀 创建maven项目后,修改pom.xml文件 <proj ...

  8. 玩转spring boot——结合JPA事务

    接着上篇 一.准备工作 修改pom.xml文件 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=&q ...

  9. 玩转spring boot——结合AngularJs和JDBC

    参考官方例子:http://spring.io/guides/gs/relational-data-access/ 一.项目准备 在建立mysql数据库后新建表“t_order” ; -- ----- ...

随机推荐

  1. 使用history.replaceState 修改url 不跳转

    history.replaceState(null,null,this.urlR);  //关键代码 history.replaceState是将指定的URL替换当前的URL 注意:用于替换掉的URL ...

  2. css样式优先级问题

    官方表述的CSS样式优先级如下: 通用选择器(*) < 元素(类型)选择器 < 类选择器 < 属性选择器 < 伪类 < ID 选择器 < 内联样式 那么,我们来举个 ...

  3. Android笔记--LayoutInflator源码和使用分析

    LayoutInflator源码分析 获取LayoutInflator对象 获取LayoutInflator的方式有两种: 使用LayoutInflator.from(Context context) ...

  4. Java抽象类、接口和内部类

    1.抽象方法.抽象类 1)抽象方法: 由abstract修饰 只有方法的定义,没有方法的具体实现(连{}都没有) 由abstract修饰的方法为抽象方法,抽象方法只有方法的定义,没有方法体实现,用一个 ...

  5. UVA 1609 Foul Play 不公平竞赛 (构(luan)造(gao)+递归)

    题意:有n支队伍(n是2的整数幂,2<=n<=4),打淘汰赛,胜者进入下一轮,其中1号队伍能打败至少一半的队伍,对于它不能打败的队伍l,一定存在一支它能够打败的队伍w,使得w能直接打败l, ...

  6. 2018.2.10 使用SSH连接远程滴滴云服务器Ubuntu (Windows下) 及 putty工具永久设置字体、颜色

    一开始会有人问云服务器是什么? 云服务器是一种类似VPS服务器的虚拟化技术, VPS是采用虚拟软件,VZ或VM在一台服务器上虚拟出多个类似独立服务器的部分,每个部分都可以做单独的操作系统,管理方法同服 ...

  7. k8s1.13.0二进制部署-Dashboard和coredns(五)

    部署UI 下载yaml文件https://github.com/kubernetes/kubernetes [root@k8s-master1 ~]# git clone https://github ...

  8. 01_1_Socket实现

    01_1_Socket实现 1.什么是MIME Multipurpos Internet Mail Extension 指明白传送内容的格式 最早用于邮件附件 2.HTTP协议基础 HTTP(Hype ...

  9. js cookie 操作

    <html> <head> <meta charset="utf-8"> <title>Javascript cookie</ ...

  10. svn提交报错,提示:locked,需要cleanup

    版权声明:本文为博主原创文章,未经博主允许不得转载. 原文地址: https://www.cnblogs.com/poterliu/p/9285137.html 在使用SVN提交代码或更新代码时经常会 ...