上下文ac获取为null,SpringContextUtil配置位置,以及各配置xml的加载顺序有讲究
发现一个有趣的现象,一般job都会在执行前去初始化一次ac,而任务监视器SupervisorQueueJob不会,因此启动时初始化ac为null,SupervisorQueueJob会始终无法获取上下文,也即其所需的bean。使得队列任务得不到执行。
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service; @SuppressWarnings("serial")
@Service("supervisorQueueJob")
public class SupervisorQueueJob extends AbstractJob { @Value("${quartz.job.autoStartup}")
protected String jobStart; protected ThreadPoolTaskExecutor jobThreadPoolTaskExecutor; @Override
protected void doExecute(JobExecutionContext context) { } @Override
protected void afterExecute(JobExecutionContext context) { } @Override
protected void beforeExecute(JobExecutionContext context) { } @Scheduled(cron = "*/10 * * * * ?")
public void triggerSupervisorTask() { if (Boolean.parseBoolean(jobStart)) {
LOGGER.info("监控线程执行一次" + System.currentTimeMillis());
jobThreadPoolTaskExecutor = (ThreadPoolTaskExecutor) ac.getBean("jobThreadPoolTaskExecutor");
jobThreadPoolTaskExecutor.submit((QueueSupervisorTask) SpringContextUtil.getBean("queueSupervisorTask"));
}
}
}
原因:
<bean class="com.wind.buy.os.manager.utils.SpringContextUtil" />加载不能在SupervisorQueueJob 初始化之后(这个不言而喻)。
还有若是需要在Controller中手动触发定时任务,则对Controller包的扫描必须也在SupervisorQueueJob 之后,一般放在dispatch-servlet.xml中。
加载顺序可以在配置文件web.xml中指定。
上下文ac获取为null,SpringContextUtil配置位置,以及各配置xml的加载顺序有讲究的更多相关文章
- web工程中web.xml元素加载顺序以及配置实例
简介 web.xml是web工程的配置文件,容器加载web工程时,会首先从WEB-INF中查询web.xml,并加载其中的配置信息,可以将web.xml认为是web工程的入口. web.xml中包含有 ...
- web.xml的加载过程配置详解
一:web.xml加载过程 简单说一下,web.xml的加载过程.当我们启动一个WEB项目容器时,容器包括(JBoss,Tomcat等).首先会去读取web.xml配置文件里的配置,当这一步骤没有 ...
- 服务器启动时Webapp的web.xml中配置的加载顺序
一 1.启动一个WEB项目的时候,WEB容器会去读取它的配置文件web.xml,读取<listener>和<context-param>两个结点. 2.紧急着,容创建一个Ser ...
- 服务器启动时Webapp的web.xml中配置的加载顺序(转载)
一 1.启动一个WEB项目的时候,WEB容器会去读取它的配置文件web.xml,读取<listener>和<context-param>两个结点. 2.紧急着,容创建一个Ser ...
- web.xml 中的listener、filter、servlet 加载顺序及其【配置详解】
在项目中总会遇到一些关于加载的优先级问题,近期也同样遇到过类似的,所以自己查找资料总结了下,下面有些是转载其他人的,毕竟人家写的不错,自己也就不重复造轮子了,只是略加点了自己的修饰. 首先可以肯定的是 ...
- web.xml的配置及加载顺序
一web.xml加载过程(步骤): 1.启动WEB项目的时候,容器(如:Tomcat)会去读它的配置文件web.xml.读两个节点: <listener></listener> ...
- Spring Boot配置加载顺序
如果加载的配置有重复的,它们的加载顺序是这样的,数字越小的优先级越高,即优先级高的覆盖优先级低的配置. Devtools global settings properties on your home ...
- SpringBoot——配置文件加载位置及外部配置加载顺序
声明 本文部分转自:SpringBoot配置文件加载位置与优先级 正文 1. 项目内部配置文件 spring boot 启动会扫描以下位置的application.properties或者applic ...
- SpringMvc项目加载顺序及上下文小结
前言: 使用springMvc已经三年了,但是内部原来一直不太了解,看到ServletConetxt和ApplicationContext头就大,趁着这几天学习,正好学习下相关的知识. 1.Servl ...
随机推荐
- Unity苹果(iOS)内购接入(Unity内置IAP)
https://www.jianshu.com/p/4045ebf81a1c Unity苹果(iOS)内购接入(Unity内置IAP) Kakarottog ...
- Nginx+ISS+Redis实现完美负载均衡
前篇文章讲到nginx是使网站采用分布式,对用户的请求采用分布式,分配到不同的服务器上,然后进行同一站点的访问,保证了访问的高效,使用率高,生命期长. 说到ISS,这里重点介绍tomcat,Tomca ...
- PHP删除目录下包含某个字符串的全部文件
//获取全部的路径 function tree(&$arr_file, $directory, $dir_name='') { $mydir = dir($directory); whi ...
- Cocoapds pod install时报错 :The sandbox is not sync with the Podfile.lock
解决方法简单:仅供其他小伙伴参考 删除项目工程本地文件夹中的xxx.workspace和Podfile.lock文件,然后重新pod install即可
- google ---gson字符串数组用GSON解析然后用逗号隔开拼接,去掉最后一个逗号
public static void main(String[] args) { String ss= "[{\"type\":\"0\",\&quo ...
- CSS(九)元素隐藏和利弊
隐藏元素.无法点击,这之间有什么关系呢? 可以配合我写的 html 食用:https://github.com/dirstart/ScriptOJ/blob/master/OJ_CSS/4.css%E ...
- Hdu 5862 Counting Intersections(有n条线段,每一条线段都是平行于x轴或者y轴,问有多少个交点+树状数组区间求和单点跟新)
传送门:Hdu 5862 Counting Intersections 题意:有n条线段,每一条线段都是平行于x轴或者y轴,问有多少个交点 分析: 基本的操作流程是:先将所有的线段按照横树坐标x按小的 ...
- Educational Codeforces Round 11 B
Description Consider 2n rows of the seats in a bus. n rows of the seats on the left and n rows of th ...
- Codeforces Round #335 (Div. 2) C
C. Sorting Railway Cars time limit pe ...
- 设置input的样式
css中的 ” 七层重叠法 ” :即网页内容先后顺序分别为:背景边框,负值z-index,display:block,浮动,display:inline-block,z-index:auto,正值z- ...