第一步:
定义SchedulerFactoryBean的applicationContextSchedulerContextKey
<bean name="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" >
<!-- 注入数据源 -->
<property name="dataSource">
<ref bean="dataSource" />
</property>
<!-- 延迟30秒启动Scheduler -->
<property name="startupDelay" value="30"></property>
<!-- 通过applicationContextSchedulerContextKey属性配置spring上下文 -->
<property name="applicationContextSchedulerContextKey">
<value>applicationContext</value>
</property>
</bean>
 
定义之后,产生的效果是:
this.scheduler.getContext().put(this.applicationContextSchedulerContextKey, this.applicationContext);
第二步:
获取到scheduler,然后从中取出applicationContext 即可
public class TestJob extends QuartzJobBean {

	@Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
Scheduler scheduler = (Scheduler) context.getScheduler();
//获取JobExecutionContext中的service对象
try {
//获取JobExecutionContext中的service对象
SchedulerContext schCtx = context.getScheduler().getContext();
//获取Spring中的上下文
ApplicationContext appCtx = (ApplicationContext)schCtx.get("applicationContext");
jobService= (JobService)appCtx.getBean("jobService");
....
} catch (SchedulerException e1) {
// TODO 尚未处理异常
e1.printStackTrace();
}
}
};


 

quartz 的job中获取到applicationContext的更多相关文章

  1. 如何在Job中获取 IOC applicationcontext

    如何在Job中获取 IOC applicationcontext https://segmentfault.com/q/1010000008002800 SpringBoot之整合Quartz调度框架 ...

  2. spring中获取applicationContext

    常用的5种获取spring 中bean的方式总结: 方法一:在初始化时保存ApplicationContext对象代码:ApplicationContext ac = new FileSystemXm ...

  3. spring mvc在Controller中获取ApplicationContext

    spring mvc在Controller中获取ApplicationContext web.xml中进行正常的beans.xml和spring-mvc.xml的配置: 需要在beans.xml中进行 ...

  4. SpringBoot项目中获取applicationContext对象

    ApplicationContext 对象是Spring开源框架的上下文对象实例,也就是我们常说的Spring容器,一般情况下我们是不用手动来管理它,而是由Spring框架自己来维护bean之间的关系 ...

  5. Spring在代码中获取bean的几种方式(转:http://www.dexcoder.com/selfly/article/326)

    方法一:在初始化时保存ApplicationContext对象 方法二:通过Spring提供的utils类获取ApplicationContext对象 方法三:继承自抽象类ApplicationObj ...

  6. quartz的job怎么获取Spring上下文

    第一步.在org.springframework.scheduling.quartz.SchedulerFactoryBean对象中注入applicationContextSchedulerConte ...

  7. Quartz 在 Spring 中如何动态配置时间--转

    原文地址:http://www.iteye.com/topic/399980 在项目中有一个需求,需要灵活配置调度任务时间,并能自由启动或停止调度. 有关调度的实现我就第一就想到了Quartz这个开源 ...

  8. tomcat启动后,在普通java类中获取spring管理的bean和ServletContext,(经过验证,可以取到)

    //从spring容易中获取bean public static Object getBean(String beanName){ ApplicationContext context = Conte ...

  9. 从Spring容器中获取Bean。ApplicationContextAware

    引言:我们从几个方面有逻辑的讲述如何从Spring容器中获取Bean.(新手勿喷) 1.我们的目的是什么? 2.方法是什么(可变的细节)? 3.方法的原理是什么(不变的本质)? 1.我们的目的是什么? ...

随机推荐

  1. HDU 2897 (博弈 找规律) 邂逅明下

    根据博弈论的两条规则: 一个状态是必胜状态当且仅当有一个后继是必败状态 一个状态是必败状态当且仅当所有后继都是必胜状态 然后很容易发现从1开始,前p个状态是必败状态,后面q个状态是必胜状态,然后循环往 ...

  2. codevs 1138 聪明的质监员

    二分+前缀和. #include<iostream> #include<cstdio> #include<cstring> #include<cmath> ...

  3. web服务器的相关资料 ngix

    OpenResty:官方网站  http://openresty.org/cn/index.html 利用nginx+lua+memcache实现灰度发布 http://www.cnblogs.com ...

  4. scala学习笔记(1):基本语法与容器

    1 var 可变,val 不可变 var (a,b) = (10,20) 分别对a,b赋值 a=10, b=20 var a,b = (10,20)则 是a=(10,20) b=(10,20) 2 L ...

  5. 【英语】Bingo口语笔记(72) - play系列

  6. csu 1326 The contest

    裸的   并查集  +  分组背包: #include<iostream> #include<cstring> #include<algorithm> #inclu ...

  7. Linux/Unix shell 自动发送AWR report(二)

    观察Oracle数据库性能,Oracle自带的awr 功能为我们提供了一个近乎完美的解决方案,通过awr特性我们可以随时从数据库提取awr报告.不过awrrpt.sql脚本执行时需要我们提供一些交互信 ...

  8. 仿Twitter登陆移动背景效果

    有使用Twitter客户端的朋友应该有发现在登录的时候,屏幕上方和下方的云朵图片是不断移动着的,再加上Twitter那支可爱的小鸟在不停的动着,给人的感觉就好像是小鸟在飞翔一样,感觉效果很不错. 我也 ...

  9. JVM内存结构之三--持久代

    本文会介绍一些JVM内存结构的基本概念,然后很快会讲到持久代,来看下Java SE 8发布后它究竟到哪去了. 基础知识 JVM只不过是运行在你系统上的另一个进程而已,这一切的魔法始于一个java命令. ...

  10. 让 PowerDesigner 支持 SQLite!

    让 PowerDesigner 支持 SQLite!   PowerDesigner是一个功能强大的数据库设计软件,最近正在用其设计新系统的数据库,但由于在项目初级阶段,希望使用轻量级的 SQLite ...