Issue
I have been banging my head on this since few days. And I really don't understand from where this error is coming from. I already followed few threads regarding this on SO, this and this one
26-Dec-2020 12:48:18.633 SEVERE [main] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class [org.springframework.web.context.ContextLoaderListener]
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:263)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:103)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4714)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5177)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:717)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:690)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:706)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:978)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1848)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
I have written a set of API and I am trying to deploy it over tomcat server. And during deployment my application is starting but getting aborted because of some other context is already there.
Why my application is not starting successfully ? I have only one war file present in my webapps folder and I have removed the rest.
I also don't understand which web.xml file is it talking about.
Solution
Finally I got the culprit. I don't know why I feel like spring session documentation needs lot of work. I could be wrong.
Anyway, I am using initializer which extends AbstractHttpSessionApplicationInitializer
, as mentioned in the documentation.
public class SessionConfigInitializer extends AbstractHttpSessionApplicationInitializer {
public SessionConfigInitializer() {
super(SessionConfig.class);
}
}
When I looked in AbstractHttpSessionApplicationInitializer
it was doing this servletContext.addListener(new ContextLoaderListener(rootAppContext));
on startup.
Posting this in case if someone else fall into this situation might help them.
Answered By - Lokesh Pandey