quarz spring boot
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的更多相关文章
- 国内最全的Spring Boot系列之二
历史文章 <国内最全的Spring Boot系列之一> 视频&交流平台 SpringBoot视频:http://t.cn/R3QepWG Spring Cloud视频:http:/ ...
- 玩转spring boot——快速开始
开发环境: IED环境:Eclipse JDK版本:1.8 maven版本:3.3.9 一.创建一个spring boot的mcv web应用程序 打开Eclipse,新建Maven项目 选择quic ...
- 【微框架】之一:从零开始,轻松搞定SpringCloud微框架系列--开山篇(spring boot 小demo)
Spring顶级框架有众多,那么接下的篇幅,我将重点讲解SpringCloud微框架的实现 Spring 顶级项目,包含众多,我们重点学习一下,SpringCloud项目以及SpringBoot项目 ...
- 玩转spring boot——开篇
很久没写博客了,而这一转眼就是7年.这段时间并不是我没学习东西,而是园友们的技术提高的非常快,这反而让我不知道该写些什么.我做程序已经有十几年之久了,可以说是彻彻底底的“程序老炮”,至于技术怎么样?我 ...
- 玩转spring boot——结合redis
一.准备工作 下载redis的windows版zip包:https://github.com/MSOpenTech/redis/releases 运行redis-server.exe程序 出现黑色窗口 ...
- 玩转spring boot——AOP与表单验证
AOP在大多数的情况下的应用场景是:日志和验证.至于AOP的理论知识我就不做赘述.而AOP的通知类型有好几种,今天的例子我只选一个有代表意义的“环绕通知”来演示. 一.AOP入门 修改“pom.xml ...
- 玩转spring boot——结合JPA入门
参考官方例子:https://spring.io/guides/gs/accessing-data-jpa/ 接着上篇内容 一.小试牛刀 创建maven项目后,修改pom.xml文件 <proj ...
- 玩转spring boot——结合JPA事务
接着上篇 一.准备工作 修改pom.xml文件 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=&q ...
- 玩转spring boot——结合AngularJs和JDBC
参考官方例子:http://spring.io/guides/gs/relational-data-access/ 一.项目准备 在建立mysql数据库后新建表“t_order” ; -- ----- ...
随机推荐
- Python使用selenium进行爬虫(一)
JAVA爬虫框架很多,类似JSOUP,WEBLOGIC之类的爬虫框架都十分好用,个人认为爬虫的大致思路就是: 1.挑选需求爬的URL地址,将其放入需求网络爬虫的队列,也可以把爬到的符合一定需求的地址放 ...
- 有关JSOUP学习分享(一)
其实现在用JSOUP爬虫的也不多了,但是由于最近换公司,做数据爬虫需要用到,就看了下,感觉还是挺好用的,原理什么的感觉和weblogic也差不到哪里去,废话少说,这里就简单的分享下最近接触的干货. J ...
- 解释器模式和php实现
解释器模式: 给定一个语言, 定义它的文法的一种表示,并定义一个解释器,该解释器使用该表示来解释语言中的句子. 角色: 环境角色:定义解释规则的全局信息. 抽象解释器::定义了部分解释具体实现,封装了 ...
- sublime text 快捷键新建.vue
第一步:添加模板: 模板写法如下: <template> </template> <script type="ecmascript-6"> &l ...
- jQuery中slim版本与普通版本的区别
在jQuery3中,推出了一个slim版本.slim,百度翻译:细长的; 苗条的,纤细的; 微小的; 无价值的. 区别概述: slim即简化版,比普通版本缺少Ajax和特效模块模块. 官方发布地址:h ...
- ArcGIS Server 10.1发布GP服务
ArcGIS Server 10.1发布GP服务 ArcGIS Server 10.1发布GP服务确实更简单了,只是刚使用不怎么习惯.ArcGIS Server 10.1发布GP服务需要先在ArcCa ...
- SqlServer 填充因子的说明
CREATE NONCLUSTERED INDEX IX_d_name ON department(d_name) with fillfactor=30 使用 fill factor 选项可以指定 M ...
- 使用jmeter测试数据库性能
出现如图所示的问题 解决办法: 1.下载驱动包,将mysql-connector-Java.jar分别放到Jmeter和Java安装目录的lib和ext目录下 链接:http://pan.baidu. ...
- HDU 5501 The Highest Mark (贪心+DP,经典)
题意: 有n道题目,每道题目的初始分数为Ai,分数每分钟减少Bi,完成此题需要Ci分钟,问在t分钟内最多能获得多少分? 思路: 好题~ 如果没有B的话,就是一道裸的01背包的题目了.每道题目的得分为: ...
- 【Python图像特征的音乐序列生成】图像特征在旋律生成中有什么用
jishude 首先援引一个资料网页:http://www.cosmosshadow.com/ml/%E5%BA%94%E7%94%A8/2016/03/01/%E9%9F%B3%E4%B9%90%E ...