搭建大佬的项目的时候遇到了一个从未遇到过的 bug,一脸懵,也不敢瞎搞,只能在百度上进行一顿搜索,但还是无济于事,先看看这个bug:
A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
……
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:493)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1423)
……
at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:953)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:872)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more
Caused by: java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/Chapter14]]
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:942)
... 8 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/Chapter14]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
... 6 more
Caused by: java.lang.IllegalArgumentException: More than one fragment with the name [spring_web] was found. This is not legal with relative ordering. See section 8.2.2 2c of the Servlet specification for details. Consider using absolute ordering.
at org.apache.tomcat.util.descriptor.web.WebXml.orderWebFragments(WebXml.java:2200)
……
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more
分享一个刚学到的解决bug的小窍门:基本上报错都是从外往内的,外面的报错都是由于内部的报错导致的,所以解决了内部的报错就可以了,越往下就是内部的错误,所以去搜解决办法的时候,先搞这个:
通过本人小学的英语水平,了解到这个是 有多个 spring_web 被找到,后面又提及到是不合法的,那么我们就要想办法去解决这个问题啦,spring_web是什么呢?我刚开始也是不知道的,原因就是添加 maven 依赖的时候直接粘贴复制,而不去管写的什么,导致啥也没记住,spring_web是我们在做项目的时候添加的依赖(jar 包),解决这个问题的方式(从我的项目来看)目前有两种(参考大佬的博客,文末有地址)。
方式一:
找到项目的 calsses 目录中的 lib:
果不其然,有两个 spring_web:
删掉一个,重新运行tomcat即可,如果在项目的 web-inf 目录的 lib 目录中也存在 不同的两个jar 包,也得删掉一个哦,要不再编译运行的时候还是会加上的。
方式二:
在web.xml 中添加如下内容:
<absolute-ordering />
而 <absolute-ordering / >能解决上述问题在于它是按绝对路径排序,它把jar包名也包括进去了,由于它们的jar包名不同,所以不改jar包的web片段名也能成功启动tomcat服务器
关于该标签具体可以看:https://blog.csdn.net/ksws0319440/article/details/104136878
大佬的解决方法:https://blog.csdn.net/pursueexcellence/article/details/89981690
希望能够帮助你解决掉困扰你多时的bug,多一个bug,多一寸的进步,加油!