上下文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 ...
随机推荐
- 关于如何在Windows下测交互题
这里的交互题指的NOI风格的交互题,即交互库 codeforces风格的交互题...只能自己实现评测插件了 使用Cena,Lemon没有附加文件功能不能评测交互题 在编译选项g++编译命令源文件中加入 ...
- 2.Valid Parentheses (括号匹配)
Level: Easy 题目描述: Given a string containing just the characters '(', ')', '{', '}', '[' and ']', ...
- UICollectionView的基本使用 collectionView
#pragma mark -- 创建CollectionView - (void)createCollectionView{ //关闭自适应 self.automaticallyAdjustsScro ...
- 74th LeetCode Weekly Contest Number of Subarrays with Bounded Maximum
We are given an array A of positive integers, and two positive integers L and R (L <= R). Return ...
- Experimental Educational Round: VolBIT Formulas Blitz B
Description The city administration of IT City decided to fix up a symbol of scientific and technica ...
- nginx配置文件企业优化
1.1 企业规范优化Nginx配置文件 第一个里程碑:创建扩展目录,生成虚拟主机配置文件 mkdir extra sed -n '10,15p' nginx.conf >extra/www.co ...
- 编译安装libimobiledevice
在windows上大家可以使用iTunes来与iPhone进行通信,但是Linux上没有这类的官方软件,所以一些爱好者就破解了iTunes的通信协议,然后在Linux上实现了该协议,也就是libimo ...
- jsonp跨域请求及本质
在html页面中,能实现跨域请求的是 第一: <script src="http://localhost:59602/JsonpTest.ashx?callBack=callBack& ...
- beleline hive spark-shell帮助
-- beeline帮助 : jdbc:hive2://100.69.216.40:10001> !help !addlocaldriverjar Add driver jar file in ...
- mysql 示例数据库安装
示例数据库不和bin安装文件在一块, 安装数据库没有这个选项 https://dev.mysql.com/doc/index-other.html