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” ; -- ----- ...
随机推荐
- where whereis locate find 的用法
1.where :where ifconfig.用来搜索命令,显示命令是否存在以及路径在哪 2.whereis:whereis vim .用来搜索程序名,而且只搜索二进制文件(参数-b).man说明文 ...
- Servlet中的初始化参数、上下文参数、以及@Resource资源注入
配置初始化参数.上下文参数.以及使用@Resource注解进行资源注入,目的是为了降低代码的耦合度.当项目需求进行变更的时候,不需要反复更改源代码,只需更改web.xml文件即可. 一:Servlet ...
- 多线程串口通信 MFC CSerialPort
写在前面: 晚上应该继续完成未写完的代码,但Chrome上打开的标签实在太多了,约30个了,必须关掉一些,所以需要把自己看的整理一下然后关掉.本次主要写点MFC环境下多线程串口通信相关的东西,这包括线 ...
- 关于dopost和doget中文乱码问题
1.doPost方法请求方式为Post 请求内容中包含请求体,因此解决方法较简单,只要改变请求体的编码即可,具体方法setCharacterEncoding("utf-8"); 2 ...
- JavaScript模板引擎的使用
为了将数据库中的一组记录转换成HTML输出到界面上,大家都采用哪些做法呢? 在WebForm时代我们经常使用datagrid.repeater,当MVC问世后我们开始直接在视图上编写C#循环语句,而现 ...
- poi实现Excel输出
/** * 第一个demo 导出Excel文件 * 第一行 第三个单元格中 写入 zhangsan */ @Test public void test1() throws IOException { ...
- Bootstrap历练实例:默认的进度条
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
- 【转】MFC编辑框自动换行,垂直滚动条自动下移
1.新建一个编辑框控件(Edit Control),将其多行(Multiline)前面打勾(属性设置为True),Auto HScroll前面的勾去掉(属性设置False),这样就可以实现每一行填满后 ...
- STL之map操作[转]
转自https://www.cnblogs.com/yutongzhu/p/5884269.html 作者彼得朱 map 是一种有序无重复的关联容器. 关联容器与顺序容器不同,他们的元素是按照关键字来 ...
- Codevs1033 蚯蚓的游戏
题目描述 Description 在一块梯形田地上,一群蚯蚓在做收集食物游戏.蚯蚓们把梯形田地上的食物堆积整理如下: a(1,1) a(1,2)…a(1,m) a(2,1) a(2,2) a(2 ...