运行我的Web应用程序时,每隔一次尝试,我都会得到下面列出的stacktrace。请注意,据我所知,在web.xml中似乎没有多个ContextLoader定义。此外,该应用程序可以在第二/第四/等位置正常运行。时间。与根本不起作用相比,此行为很难调试。谁能对此有所启发?
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)
对于有类似问题的任何人-事实证明,该项目中使用的spring-jersey正在建立自己的环境。我的上下文和春季球衣显然是按随机顺序初始化的。此处的更多信息:
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>
作为web.xml中的firt参数,请确保在初始化上下文之前对其进行设置。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句