spring-mvc出现:More than one fragment with the name [spring_web] was found

搭建大佬的项目的时候遇到了一个从未遇到过的 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,多一寸的进步,加油!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

潘小蓝

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值