Java.lang.IllegalStateException: Cannot initialize context because application root context is already present

When I launch my webapp, I get the stacktrace specified below for every other attempt. Note that, as far as I can tell, there are several definitions of ContextLoader im web.xml. In addition, the application works fine, second / fourth / etc. time. This behavior is much harder to debug than if it just didn't work. Can anyone shed some light on this?

 java.lang.IllegalStateException: Cannot initialize context because there is already a root application context present - check whether you have multiple ContextLoader* definitions in your web.xml!
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:299)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4795)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5221)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:919)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1703)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
+4
source share
2 answers

, , , spring -jersey, , . spring -jersey one . :
https://java.net/jira/browse/JERSEY-2038
https://java.net/projects/jersey/lists/users/archive/2014-03/message/124
:

servletContext.setInitParameter("contextConfigLocation", "<NONE>");

WebAppInitializer - . xml:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value></param-value>
</context-param> 

firt web.xml, , .

+4

, , spring boot

  container.addListener(new ContextLoaderListener(rootContext));
0

Source: https://habr.com/ru/post/1615268/


All Articles