Java 发现了不止一个名为 [spring_web] 的片段。这对于相对排序是不合法的
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/54290263/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
More than one fragment with the name [spring_web] was found. This is not legal with relative ordering
提问by user2054833
I have a spring boot application that works fine when I run it using the embedded server from Intellj. However, when I package it into .war file and deploy it on tomcat I get the following error:
我有一个 Spring Boot 应用程序,当我使用 Intellj 的嵌入式服务器运行它时,它运行良好。但是,当我将其打包成 .war 文件并将其部署在 tomcat 上时,出现以下错误:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/file-upload-0.0.1-SNAPSHOT]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
at
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:985)
at
org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1857)
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:1149)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
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.tomcat.util.descriptor.web.WebXml.orderWebFragments(WebXml.java:2159)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1124)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:769)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:299)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:94)
at
org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5176)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 10 more
21-Jan-2019 01:51:04.709 SEVERE [localhost-startStop-1]
org.apache.catalina.startup.HostConfig.deployWAR Error deploying web application archive [C:\Users\dennismo\Dev\Projects\Production Prep\file-upload-module\webapps\file-upload-0.0.1-SNAPSHOT.war]
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/file-upload-0.0.1-SNAPSHOT]]
at
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:758)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:985)
at
org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1857)
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:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
My project does not contain multiple web-fragment so I don't know what could be causing this problem.
我的项目不包含多个网络片段,所以我不知道是什么导致了这个问题。
pom.xml
pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
<relativePath/> <!-- lookup parent from salaryPaymentRequestRepo -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<akka.version>2.5.17</akka.version>
</properties>
<repositories>
<repository>
<id>default</id>
<url>http://repo.maven.apache.org/maven2</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.197</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.univocity</groupId>
<artifactId>univocity-parsers</artifactId>
<version>2.7.6</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.fasterxml.Hymanson.dataformat</groupId>
<artifactId>Hymanson-dataformat-xml</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>26.0-jre</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.23.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.11.0</version>
</dependency>
<dependency>
<groupId>ma.glasnost.orika</groupId>
<artifactId>orika-core</artifactId>
<version>1.4.2</version><!-- or latest version -->
<exclusions>
<exclusion>
<artifactId>javassist</artifactId>
<groupId>org.javassist</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_2.12</artifactId>
<version>${akka.version}</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-stream_2.12</artifactId>
<version>${akka.version}</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-persistence_2.12</artifactId>
<version>${akka.version}</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-testkit_2.12</artifactId>
<version>${akka.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.2</version>
<scope>system</scope>
<systemPath>${basedir}/src/main/resources/lib/ojdbc7-12.1.0.jar</systemPath>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
采纳答案by David Simonsbacka
Sounds like you have two different versions of Spring, check your dependencies to see if you have a dependency to another Spring-version.
听起来您有两个不同版本的 Spring,请检查您的依赖项以查看您是否对另一个 Spring 版本有依赖项。
mvn dependency:tree -Dverbose -Dincludes=groupId:artifactId
回答by Pardha Saradhi
This problem was solved by adding absolute ordering of deployment descriptors.
通过添加部署描述符的绝对顺序解决了这个问题。
The tag <absolute-ordering/>
was added to the web.xml
标签<absolute-ordering/>
被添加到 web.xml
Reference:
参考:
https://www.oracle.com/technetwork/articles/javaee/javaee6overview-part2-136353.html
https://www.oracle.com/technetwork/articles/javaee/javaee6overview-part2-136353.html
回答by rohan
I had the same problem and solved it. Got similar errors but not used spring boot. I have used spring 3.x with java 8. If above solutions are not working change the jars and search whether those jars are compatible with the java version you are using or not. spring 3.x is not compatible with java 8.
我遇到了同样的问题并解决了它。有类似的错误,但没有使用弹簧靴。我在 java 8 中使用了 spring 3.x。如果上述解决方案不起作用,请更改 jars 并搜索这些 jars 是否与您使用的 java 版本兼容。spring 3.x 与 java 8 不兼容。
回答by Roman Sterlin
add <absolute-ordering />
tag to your web.xml
just under the <display-name>
tag.
should work.
在<absolute-ordering />
标签web.xml
下添加<display-name>
标签。应该管用。
回答by u1776024
This error seems to happen after project's spring framework update, clearing the project history file in tomcat webapps
may solve the problem.
这个错误好像是项目的spring框架更新后出现的,在tomcat中清除项目历史文件webapps
可能会解决问题。
回答by Pran Sukh
I am using spring 5.1.8 and apache tomcat 8.5 version.
In my web.xml
file i have added the add <absolute-ordering />
right after the <display-name>
tag and this worked for me.
我使用的是 spring 5.1.8 和 apache tomcat 8.5 版本。在我的web.xml
文件中,我<absolute-ordering />
在<display-name>
标签之后添加了 add ,这对我有用。
回答by antara chakraborty
add a absolute-ordering
tag to your web.xmljust under the display-name
tag should work. - This answer by Roman Sterlin worked for me too.
在absolute-ordering
标签下添加一个标签到你的web.xmldisplay-name
应该可以工作。- Roman Sterlin 的这个答案也对我有用。
回答by Lehar Bhandari
Cleaning the server worked for me. Just do the following :
清洁服务器对我有用。只需执行以下操作:
Right click on the server -> Clean.
右键单击服务器 -> 清理。
Then redeploy the app on the server.
然后在服务器上重新部署应用程序。
回答by Raghu Reddy
My project is Springboot based version (1.5.21.RELEASE) and generating war and deploying in physical tomcat. I had gotten the same issue and got resolved with below approach.
我的项目是基于 Springboot 的版本 (1.5.21.RELEASE) 并在物理 tomcat 中生成战争和部署。我遇到了同样的问题,并通过以下方法得到了解决。
Solution: Exclude tomcat-embed-websocket dependency from spring-boot-starter-web in the pom.xml
解决方案:在 pom.xml 中从 spring-boot-starter-web 中排除 tomcat-embed-websocket 依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring.boot.version}</version>
<exclusions>
**<exclusion>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-websocket</artifactId>
</exclusion>**
</exclusions>
</dependency>
回答by Anuj Panwar
This error generally comes from that if we have two copy of spring in our container, which get loaded by different class loaders(in my case shared class loader and webapp class loader).
这个错误通常来自如果我们的容器中有两个 spring 副本,它们由不同的类加载器加载(在我的例子中是共享类加载器和 webapp 类加载器)。
Check effective pom, if you have any bundle embed spring jars/classes, if so remove it, you should use the one installed as bundle from container.
检查有效的 pom,如果您有任何包嵌入弹簧罐/类,如果有,请将其删除,您应该使用从容器中作为包安装的那个。