java.lang.IllegalStateException: Cannot initialize context because there is already a root application context present

◇◆丶佛笑我妖孽 提交于 2019-12-01 19:01:31

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.

Make sure that you are not doing this if you are using spring boot

  container.addListener(new ContextLoaderListener(rootContext));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!