quartz 的job中获取到applicationContext
- 第一步:
- 定义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的更多相关文章
- 如何在Job中获取 IOC applicationcontext
如何在Job中获取 IOC applicationcontext https://segmentfault.com/q/1010000008002800 SpringBoot之整合Quartz调度框架 ...
- spring中获取applicationContext
常用的5种获取spring 中bean的方式总结: 方法一:在初始化时保存ApplicationContext对象代码:ApplicationContext ac = new FileSystemXm ...
- spring mvc在Controller中获取ApplicationContext
spring mvc在Controller中获取ApplicationContext web.xml中进行正常的beans.xml和spring-mvc.xml的配置: 需要在beans.xml中进行 ...
- SpringBoot项目中获取applicationContext对象
ApplicationContext 对象是Spring开源框架的上下文对象实例,也就是我们常说的Spring容器,一般情况下我们是不用手动来管理它,而是由Spring框架自己来维护bean之间的关系 ...
- Spring在代码中获取bean的几种方式(转:http://www.dexcoder.com/selfly/article/326)
方法一:在初始化时保存ApplicationContext对象 方法二:通过Spring提供的utils类获取ApplicationContext对象 方法三:继承自抽象类ApplicationObj ...
- quartz的job怎么获取Spring上下文
第一步.在org.springframework.scheduling.quartz.SchedulerFactoryBean对象中注入applicationContextSchedulerConte ...
- Quartz 在 Spring 中如何动态配置时间--转
原文地址:http://www.iteye.com/topic/399980 在项目中有一个需求,需要灵活配置调度任务时间,并能自由启动或停止调度. 有关调度的实现我就第一就想到了Quartz这个开源 ...
- tomcat启动后,在普通java类中获取spring管理的bean和ServletContext,(经过验证,可以取到)
//从spring容易中获取bean public static Object getBean(String beanName){ ApplicationContext context = Conte ...
- 从Spring容器中获取Bean。ApplicationContextAware
引言:我们从几个方面有逻辑的讲述如何从Spring容器中获取Bean.(新手勿喷) 1.我们的目的是什么? 2.方法是什么(可变的细节)? 3.方法的原理是什么(不变的本质)? 1.我们的目的是什么? ...
随机推荐
- jsp之jsp基础
1. Jsp生命周期 客户端第一次请求->web容器把jsp文件转译为servlet源文件(java)->编译为class文件->载入class文件生成servlet对象 2. Js ...
- 将js对象转为json对象属性加上引号
工具地址 http://js2json.mengxiangchaoren.com
- 51nod1225 余数之和
打表可以看出规律.分块求就可以了. #include<cstdio> #include<cstring> #include<cctype> #include< ...
- Storm中tuple的可靠性
一.简介 Storm 可以保证 spout 发出的每条消息都能被“完全处理” ,这也是直接区别于其他实时系统的地方,如 S4. 请注意,spout 发出的消息后续可能会触发产生成千上万条消息 ,可以形 ...
- Ubuntu中文输入法的安装
Ubuntu上的输入法主要有小小输入平台(支持拼音/二笔/五笔等),Fcitx,Ibus,Scim等.其中Scim和Ibus是输入法框架. 在Ubuntu的中文系统中自带了中文输入法,通过Ctrl+S ...
- python - 简明 性能测试
简洁测试: # python -m cProfile test.py 代码注入: # -*- coding: utf-8 -*- class test(object): pass class test ...
- LCS nlog(n) 但最坏情况还是比较悲剧 转载的文章;
最长公共子序列问题: 给定2个字符串,求其最长公共子串.如abcde和dbada的最长公共字串为bd. 动态规划:dp[i][j]表示A串前i个和B串前j个的最长公共子串的长度. 则 若A[i] == ...
- Oracle时间函数numtoyminterval()
格式:NumToYMInterval(n, interval_unit); n: 数值类型 interval_unit: 'YEAR', 'MONTH' ,或其他可以转换成这两个值之一的表达式 N ...
- 基于CentOS与VmwareStation10搭建Oracle11G RAC 64集群环境:4.安装Oracle RAC FAQ-4.6.重新配置与缷载11R2 Grid Infrastructure
1.[root@linuxrac1 ~]# /u01/app/oraInventory/orainstRoot.sh 2.[root@linuxrac2 ~]# /u01/app/oraInvento ...
- 树莓派 不稳定 ssh经常断 解决
确保供电没问题,供电至少要0.7A,如果USB口有接东西就要更多 几个提高树莓派网络稳定性的方法 TroubleShooting(推荐!好多问题的解决方案) 设置树莓派SSH连接因超时闲置断开 树莓派 ...