58

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>
user2054833
  • 2,115
  • 7
  • 24
  • 39
  • Seems this is a change introduced in tomcat 7.0.93 FWIW... – rogerdpack Jul 06 '20 at 20:19
  • If you use JAVA configuration, find your answer at https://stackoverflow.com/questions/57626140/spring-boot-java-lang-illegalargumentexception-more-than-one-fragment-with-th/64952792#64952792. – Umer Khalid Nov 22 '20 at 10:00

25 Answers25

99

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

Roman Sterlin
  • 1,485
  • 3
  • 10
  • 25
  • 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 https://stackoverflow.com/questions/57332888 – DavesPlanet Aug 02 '19 at 20:12
  • I am using java based configuration and i don't have any xml files, then what should i do?? – KJEjava48 Aug 18 '19 at 16:42
  • 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 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. – Michael Stalcup Aug 20 '19 at 15:01
  • @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. – KJEjava48 Aug 23 '19 at 16:07
37

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

Right click on the server -> Clean.

Then redeploy the app on the server.

Lehar Bhandari
  • 488
  • 4
  • 6
24

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
  • what is the use of mvn dependency:tree -Dverbose -Dincludes=groupId:artifactId . Where should i use this ?? – KJEjava48 Aug 18 '19 at 16:42
  • Run it in your terminal at Maven project root to locate conflicting dependencies. [Official Maven documentation](https://maven.apache.org/plugins/maven-dependency-plugin/examples/resolving-conflicts-using-the-dependency-tree.html) – David Simonsbacka Aug 19 '19 at 17:32
  • For gradle you can use the dependencyInsight option, more found in the [documentation](https://docs.gradle.org/current/userguide/inspecting_dependencies.html). – David Simonsbacka Aug 26 '19 at 06:13
  • How to use dependencyInsight option in gradle,where should i find it?? That link is not working – KJEjava48 Oct 06 '20 at 06:34
  • 2
    had this bug in IntelliJ (it did not remove the previous Spring version which was indicated in pom.xml after an upgrade) – John Donn Apr 05 '22 at 07:53
  • According to @JohnDonn comment, 1. removed spring artifacts from .m2. 2. invalidate and cleared cache from InteliJ Worked for me ! – jayaneetha Jun 06 '22 at 23:04
  • 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] – hello_earth Jan 31 '23 at 17:15
15

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.

Joe Hunt
  • 161
  • 2
  • 5
11

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

Silvano Cerza
  • 954
  • 5
  • 16
  • 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. – Robert Watkins Oct 18 '19 at 01:53
  • I get that errors updating Spring 2.3.1 to any upper version. Also cleaning webapp folder did not make the trick for me. – Michael Hegner Dec 17 '20 at 12:00
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

  • 4
    Really added to `pom.xml` instead of `web.xml`? – Selaron Mar 15 '19 at 07:39
  • @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. – KJEjava48 Aug 23 '19 at 16:07
  • @KJEjava48 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. – Pardha Saradhi Sep 10 '19 at 10:18
6

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.

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.

Anuj Panwar
  • 113
  • 7
  • 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. – user11153 Jan 26 '22 at 11:59
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.

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

Carlos
  • 105
  • 2
  • 6
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)

rogerdpack
  • 62,887
  • 36
  • 269
  • 388
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>
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

grandfree
  • 11
  • 2
  • 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](/help/how-to-answer). – Community Jul 22 '22 at 03:51
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.

rohan
  • 151
  • 1
  • 7
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.

Kacper Cichecki
  • 540
  • 5
  • 12
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>
Smart Coder
  • 1,435
  • 19
  • 19
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.

Mauricio Zárate
  • 440
  • 1
  • 4
  • 8
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.

Timoteo Ponce
  • 510
  • 9
  • 27
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.

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.

Bass
  • 195
  • 1
  • 2
  • 9
0

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

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.

lord5et
  • 422
  • 7
  • 6
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

Overdrowsed
  • 107
  • 7
-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.