java.lang.IllegalStateException: Cannot initialize context because there is already a root application context present
@Controller
@ComponentScan
@Configuration
@EnableScheduling
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class, RedisAutoConfiguration.class, MybatisAutoConfiguration.class})
@ImportResource(locations = {"classpath*:app.xml"})
public class AppMain extends SpringBootServletInitializer implements ApplicationContextAware {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
// return super.configure(builder);
return builder.sources(AppMain.class);
} @Override
public void onStartup(ServletContext servletContext) throws ServletException {
servletContext.setInitParameter("logSystem","log4j,logback");
servletContext.setInitParameter("loggingLevel", "INFO");
servletContext.setInitParameter("loggingCharset", "UTF-8");
servletContext.setInitParameter("contextConfigLocation", "<NONE>");
super.onStartup(servletContext);
}
}
For anyone with a similar problem - turns out that spring-jersey used in the project was setting up its own context. My context and the spring-jersey one were initialized in random order apparently. More info here:
https://java.net/jira/browse/JERSEY-2038
https://java.net/projects/jersey/lists/users/archive/2014-03/message/124
The suggested solution of adding:
servletContext.setInitParameter("contextConfigLocation", "<NONE>");
In WebAppInitializer implementation didn't work reliably due to initialization order. What solved the problem was adding its xml equivalent:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</context-param>
as the firt parameter in web.xml, ensuring that its set before the context is initialized.
java.lang.IllegalStateException: Cannot initialize context because there is already a root application context present的更多相关文章
- java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context 错误
spring boot 项目启动报错:原因一般是注入了相同名字的service -- :: com.gxcards.mes.MainWwwWeb: logStartupProfileInfo INFO ...
- tomcat启动时检测到循环继承而栈溢出的问题:Caused by: java.lang.IllegalStateException: Unable to complete the scan for annotations for web application [/test] due to a StackOverflowError. Possible root causes include
最近在公司更新一个老项目的时候,发现部署项目后tomcat报错,错误如下: Caused by: java.lang.IllegalStateException: Unable to complete ...
- Caused by: java.lang.IllegalStateException: Unable to complete the scan for annotations for web application [/Cppcc] due to a StackOverflowError. Possible root causes include a too low setting for -Xs
解决办法:(1)修改D:\Java\apache-tomcat-7.0.88\conf\catalina.properties (122line) (2)如org.apache.catalina.st ...
- tomcat启动报错:java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException:
tomcat日志: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start com ...
- spring低版本报错:java.lang.IllegalStateException: Context namespace element ‘annotation-config’ and its parser class [*] are only available on
参考来源:http://blog.csdn.net/sunxiaoyu94/article/details/50492083 使用spring低版本(2.5.6),使用jre 8发现错误: Unexp ...
- nested exception is java.lang.IllegalStateException: Context namespace element 'annotation-config' a
公司还用的是spring低版本,今天用jre 8测试了一下,发现错误: Unexpected exception parsing XML document from class path resour ...
- scw——01 java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMake
错误: java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.Mock ...
- java.lang.IllegalStateException: class utils.filter.ContentFilter is not a javax.servlet.Filter
1.错误描写叙述 2016-01-12 11:27:01.787:WARN:oejuc.AbstractLifeCycle:FAILED ContentFilter: java.lang.Illega ...
- eclipse启动报错java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' befo
报错: java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invo ...
随机推荐
- Centos7之pacemaker高可用安装配置详解
申明: centos7的pacemaker与6使用的方法不一致,即使用centos6.x的方法在centos7.x上面配置pacemaker不能成功. 因此openstack 上面的centos7.1 ...
- 遵循统一的机器学习框架理解SVM
遵循统一的机器学习框架理解SVM 一.前言 我的博客仅记录我的观点和思考过程.欢迎大家指出我思考的盲点,更希望大家能有自己的理解. 本文参考了李宏毅教授讲解SVM的课程和李航大大的统计学习方法. 二. ...
- csu 1909: Perfect Chocolate
1909: Perfect Chocolate Submit Page Summary Time Limit: 3 Sec Memory Limit: 128 Mb Submi ...
- fastadmin 后台view data-source关联报500错误问题
data-source 关联模型通过id关联被关联表的name字段,没有name字段就报500
- AtCoder整理(持续更新中……)
做了那么久的atcoder觉得自己的题解发的很乱 给有想和我一起交流atcoder题目(或者指出我做法的很菜)(或者指责我为什么整场比赛只会抄题解)的同学一个索引的机会??? 于是写了个爬虫爬了下 A ...
- matplotlib笔记1
散点图-scatter 散点图显示两组数据的值,每个点的坐标位置由变量的值决定由一组不连接的点完成,用于观察两种变量的相关 import numpy as np import matplotlib.p ...
- 关于mq的思考
解耦场景 spark 发告警,同过kafka来解耦 削峰场景 日志采集生产环境几百台,当后续数量持续增加时,如果不加消息队列或者内存队列,可能把数据库打死 一个中间件: 为什么用 ->解决什么问 ...
- C#如何调用C++(进阶篇)
上一篇文章最后,提出的一个问题:如果一个c++库中有很多方法,需要一个个声明??这样岂不是要写很多代码??,而且没有智能提示看到提供了那些方法. 如下图: 如果有朋友需要用这种方式调用,而又不知道怎么 ...
- 微软升级 WSL Window Subsystem for Linux Win10系统自带Linux
在设计之初,微软就允许类似于Win32这种子系统运行于windows NT内核之上,它可以为上层应用提供编程接口,同时避免应用去实现内核里的一些调用细节.NT内核的设计在最开始就可以支持POSIX,O ...
- 文件导出Excel、Word、Pdf
如果要将查询结果导出Excel,只要将页面的Context-Type修改下: header( "Content-Type: application/vnd.ms-excel"> ...