More than one fragment with the name [spring_web] was found. This is not legal with relative ordering
Asked Answered
S

26

60

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:

    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

<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.jackson.dataformat</groupId>
            <artifactId>jackson-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>
Snip answered 21/1, 2019 at 12:43 Comment(2)
Seems this is a change introduced in tomcat 7.0.93 FWIW...Diandrous
If you use JAVA configuration, find your answer at #57626640.Facula
D
25

Sounds like you have two different versions of Spring, check your dependencies to see if you have a dependency to another Spring-version.

mvn dependency:tree -Dverbose -Dincludes=groupId:artifactId
Dittmer answered 23/1, 2019 at 7:56 Comment(7)
what is the use of mvn dependency:tree -Dverbose -Dincludes=groupId:artifactId . Where should i use this ??Sergo
Run it in your terminal at Maven project root to locate conflicting dependencies. Official Maven documentationDittmer
For gradle you can use the dependencyInsight option, more found in the documentation.Dittmer
How to use dependencyInsight option in gradle,where should i find it?? That link is not workingSergo
had this bug in IntelliJ (it did not remove the previous Spring version which was indicated in pom.xml after an upgrade)Guess
According to @JohnDonn comment, 1. removed spring artifacts from .m2. 2. invalidate and cleared cache from InteliJ Worked for me !Bohemia
this will also happen if you reference a shaded jar with spring dependencies and also reference the same spring dependencies in your main application. well shading spring dependencies is an awful idea, i guess. [note to self] [see some of the below answers too]Athabaska
O
100

add <absolute-ordering /> tag to your web.xml just under the <display-name> tag. should work.

Opinionative answered 31/3, 2019 at 21:42 Comment(5)
Excellent! It was a critical part of the solution we needed and we could not have done it without you. I posted our full solution at stackoverflow.com/questions/57332888Drislane
I am using java based configuration and i don't have any xml files, then what should i do??Sergo
For anyone wanting more information, I had the same exception which also said "See section 8.2.2 2c of the Servlet specification for details. Consider using absolute ordering."... here is that section: c. Duplicate name exception: if, when traversing the web-fragments, multiple members with the same <name> element are encountered, the application must log an informative error message including information to help fix the problem, and must fail to deploy. For example, one way to fix this problem is for the user to use absolute ordering, in which case relative ordering is ignored.Pitiless
@Roman Sterlin I have the same error, but i can't use your solution bcos it's on my spring boot application where i don't need to use a web.xml.Then what will i do to solve this.Sergo
This worked as a temporary solution, but it ultimately caused deployment issues on my production server. The problem was only in my build environment, which just needed old files to be deleted.Extinct
B
41

Cleaning the server worked for me. Just do the following :

Right click on the server -> Clean.

Then redeploy the app on the server.

Berlin answered 30/7, 2019 at 21:28 Comment(2)
I didn't find the icon to click, while a mvn clean install solve the issue for me as well.Dalenedalenna
./gradlew clean worked for mePatric
D
25

Sounds like you have two different versions of Spring, check your dependencies to see if you have a dependency to another Spring-version.

mvn dependency:tree -Dverbose -Dincludes=groupId:artifactId
Dittmer answered 23/1, 2019 at 7:56 Comment(7)
what is the use of mvn dependency:tree -Dverbose -Dincludes=groupId:artifactId . Where should i use this ??Sergo
Run it in your terminal at Maven project root to locate conflicting dependencies. Official Maven documentationDittmer
For gradle you can use the dependencyInsight option, more found in the documentation.Dittmer
How to use dependencyInsight option in gradle,where should i find it?? That link is not workingSergo
had this bug in IntelliJ (it did not remove the previous Spring version which was indicated in pom.xml after an upgrade)Guess
According to @JohnDonn comment, 1. removed spring artifacts from .m2. 2. invalidate and cleared cache from InteliJ Worked for me !Bohemia
this will also happen if you reference a shaded jar with spring dependencies and also reference the same spring dependencies in your main application. well shading spring dependencies is an awful idea, i guess. [note to self] [see some of the below answers too]Athabaska
G
16

I had the same problem when building a war file with maven because I did not clean before packaging and maven was including multiple versions of spring jar files from previous builds.

Greatcoat answered 11/5, 2020 at 15:2 Comment(0)
C
12

This error seems to happen after project's spring framework update, clearing the project history file in tomcat webapps may solve the problem.

Castellan answered 28/6, 2019 at 8:36 Comment(2)
Yeah, this worked for me as well. Esp. in development, the WEB-INF/lib directory of the deployed webapp isn't emptied just because of a redeploy - you need to clean it. So if you upgrade Spring, you can get multiple versions in the lib dir temporarily.Acidfast
I get that errors updating Spring 2.3.1 to any upper version. Also cleaning webapp folder did not make the trick for me.Gilt
A
9

This problem was solved by adding absolute ordering of deployment descriptors.

The tag <absolute-ordering/> was added to the web.xml

Reference:

https://www.oracle.com/technetwork/articles/javaee/javaee6overview-part2-136353.html

Attribution answered 13/2, 2019 at 17:36 Comment(3)
Really added to pom.xml instead of web.xml?Untutored
@Pardha Saradhi I have the same error, but i can't use your solution bcos it's on my spring boot application where i don't need to use a web.xml.Then what will i do to solve this.Sergo
@Sergo I have no idea how we can achieve it on spring. I have done it with the help of process followed from the attached link. If you find any solution to it, post it. It'll be helpful to others.Attribution
G
9

I had this occur after I updated the Spring Framework version in a Maven project. I was finally able to resolve the issue by running mvn clean, apparently the old Spring JARs were being picked up somewhere under target.

Galahad answered 18/8, 2020 at 13:28 Comment(0)
D
4

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).

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.

Diaconal answered 3/2, 2020 at 10:51 Comment(1)
Correct answer for my case. This happens if you have two copies of same library - one in WEB-INF/lib inside WAR, other one inside Tomcat shared lib catalog.Turmel
G
4

If you manually adds all the Jars then you have to delete WEB-INF/lib/spring-web-5.2.9.RELEASE-sources.jar or similar jar file (may be your jar version will be different). Once you delete that jar tomcat will start working.

Goldin answered 20/3, 2021 at 11:46 Comment(0)
K
2

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.

Solution: Exclude tomcat-embed-websocket dependency from spring-boot-starter-web in the pom.xml

<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>
Kame answered 30/10, 2019 at 7:16 Comment(0)
N
2

Just an answer from newbbie to newbbies:

Make sure you place web.xml inside /WebContent/WEB-INF.

I placed it inadvertently in /WebContent (not /WEB-INF), and almost got crazy trying to unsuccessfully apply some of the proposed solutions, the error message was exactly the same.

Nickey answered 22/5, 2020 at 8:20 Comment(1)
It should "end up" in your_tomcat/webapps/your_webapp_name/WEB-INF/web.xml FWIWDiandrous
D
2

For me this meant that I was including some "shaded jars" that bundled copies of spring within them. So all the same "spring version" but multiple copies of spring causes this.

You can check if this is the case by going to tomcat/webapps/your_webapp/WEB-INF/lib, unjarring all the jars, and searching for "spring_web"

ex:

# first unjar everything then

WEB-INF/lib $ grep spring_web . -r

spring-web-4.3.12.RELEASE/META-INF/web-fragment.xml
7:  <name>spring_web</name>

some_other_shaded_jar/META-INF/web-fragment.xml
7:  <name>spring_web</name>

If this is the case you'd need to use the absolute fix of the other answers or not include multiple copies of spring somehow.

Seems this is a change introduced in tomcat 7.0.93 FWIW (so it didn't throw this failure in earlier versions of tomcat 7)

Diandrous answered 8/7, 2020 at 15:20 Comment(2)
This method helped me to identify easilyInquisition
if too lazy to unjar everything, just grep for "spring" in your lib folder and you are in for some surprisesAthabaska
D
1

Your web.xml should look like this (added <absolute-ordering/> inside the tag web-app tag)

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>Archetype Created Web Application</display-name>
  <absolute-ordering/>
</web-app>
Diplostemonous answered 26/5, 2022 at 7:54 Comment(0)
C
1

If you have previously built the project with another version and then changed the version and tried to build again, this exception is thrown. You can delete the target folder in your application. If you still get an exception, you can go to the project directory from the terminal and type mvn clean install

Chantey answered 20/7, 2022 at 8:45 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Baggott
C
0

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.

Chirm answered 16/3, 2019 at 10:29 Comment(0)
R
0

I solved similar problem by removing all my apps (I had there two different apps) from webapps folder and then redeployed my war file.

Renny answered 18/4, 2020 at 22:48 Comment(0)
J
0

I had to add this in web.xml to make it work :

<absolute-ordering>
    <name>fragment_name_if_required</name>
    <others></others>
</absolute-ordering>
Jae answered 28/7, 2020 at 21:50 Comment(0)
E
0

All these answers are great but also check if "Apache CXF" lib is in your classpath, it apparently conflicts with Spring Web 5.2.3, for me I temporary removed because I'm actually not using it and now my project is running okay.

Eyecup answered 20/8, 2020 at 16:58 Comment(0)
L
0

For me, this issue happened when Tomcat was not properly installed .I have reinstalled and updated the installation path at:

eclipse window->preferences->runtime ENV -> path of the newly installed tomcat 

After setting the correct path, it worked fine.

Lesson answered 21/6, 2021 at 16:58 Comment(0)
A
0

For me , it was because of 2 spring-web jars i.e. spring-web-5.02-release.jar and spring-web-sources-5.02-release.jar in build path. By removing spring-web-sources-5.02-release.jar, issue is solved.

Acquit answered 25/9, 2021 at 14:30 Comment(0)
B
0

Had the same issue and wanted to get to the root cause. I knew spring-web jar's fragment is called 'spring_web'. However my source code did not have 'spring_web' fragment anywhere else. So I used a tool (jfind) to search for 'spring_web' through an expanded form of my EAR that was generated at build time. Surprisingly, 'spring_web' was found in another project's web-fragment jar that was generated at build time. On resolving this second occurrence, the issue was gone. So it seems to be due to duplicate 'spring_web' fragment and we need to have just one.

Bologna answered 8/11, 2021 at 18:33 Comment(0)
F
0

Remove all the unused dependencies from the lib folder. Now try to rerun the application on the server. Hope it will work now.

Flimsy answered 31/10, 2022 at 5:51 Comment(0)
N
0

I was fighting with this few hours. Solution for me was to invalidate IntelliJ cache. This problem showed up when I was in the process of upgrading spring framework. Intellij was packaging two versions of the same library and that's why I was getting an error.

Neotropical answered 2/2, 2023 at 23:8 Comment(0)
B
0

This happened to me when I changed the version of one of the dependencies in pom.xml, undeploying and deploying the webapp fixed it for me

Biskra answered 5/2, 2023 at 16:1 Comment(0)
H
0

In my case, it is caused by duplicated spring-web lib. When I read the error stack, It contains a message like below:

Consider using absolute ordering. Duplicate fragments found in [..spring-web-5.2.12.RELEASE.jar, ..my_submodule.jar]

[..] indicates that I need check conflicts in these jars.

Finally I change spring-web scope as provided in my my_submodule.jar to resolve this issue.

Hittel answered 26/10, 2023 at 6:33 Comment(0)
S
-1

See the below Line in error log:

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.   

which says to use absolute ordering. So, you have to add <absolute-ordering/> tag in your web.xml file inside <web-app> tag.

Streamy answered 14/8, 2021 at 11:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.