Spring 在 tomcat7 上部署为 war 的启动应用程序失败并出现错误 "More than one fragment with the name [org_apache_tomcat_websocket] was found"

Spring boot app deployed as war on tomcat7 fails with error "More than one fragment with the name [org_apache_tomcat_websocket] was found"

在 tomcat7 上部署我的 spring-boot 应用程序失败,从错误中可以看出它是由以下原因引起的:

More than one fragment with the name [org_apache_tomcat_websocket] 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

我尝试删除重复的依赖项,但没有成功

这是我的 build.gradle

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.21.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
apply plugin: 'application'

jar {
    baseName = 'gs-interswitch-verve-mobile-service'
    version =  '0.1.0'
}

repositories {
    mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8
mainClassName="verve.Application"

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web:1.5.21.RELEASE")
    testCompile("junit:junit")
    testCompile('org.springframework.boot:spring-boot-starter-test:1.5.21.RELEASE')
    compile("org.apache.httpcomponents:httpclient:4.0-beta1")
    compile("org.json:json:20140107")
    compile("org.bouncycastle:bcpkix-jdk15on:1.49")
    compile("com.google.code.gson:gson:2.8.5")
    compileOnly("org.springframework.boot:spring-boot-starter-tomcat:1.5.21.RELEASE")RELEASE
}

我希望应用程序能够成功部署,但我遇到了下面显示的错误

Jun 07, 2019 11:53:53 AM org.apache.catalina.startup.HostConfig undeploy
INFO: Undeploying context [/InterswitchVerveMobile]
Jun 07, 2019 11:53:53 AM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /Applications/tomcat7/webapps/InterswitchVerveMobile.war
Jun 07, 2019 11:53:53 AM org.apache.catalina.loader.WebappClassLoaderBase validateJarFile
INFO: validateJarFile(/Applications/tomcat7/webapps/InterswitchVerveMobile/WEB-INF/lib/tomcat-embed-core-8.5.40.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class
Jun 07, 2019 11:53:53 AM org.apache.catalina.loader.WebappClassLoaderBase validateJarFile
INFO: validateJarFile(/Applications/tomcat7/webapps/InterswitchVerveMobile/WEB-INF/lib/tomcat-embed-el-8.5.40.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/el/Expression.class
Jun 07, 2019 11:53:53 AM org.apache.catalina.core.ContainerBase addChildInternal
SEVERE: ContainerBase.addChild: start: 
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/InterswitchVerveMobile]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1018)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:994)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1127)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:2020)
    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:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalArgumentException: More than one fragment with the name [org_apache_tomcat_websocket] 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.catalina.deploy.WebXml.orderWebFragments(WebXml.java:2338)
    at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1268)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:881)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:388)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5606)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    ... 10 more

Jun 07, 2019 11:53:54 AM org.apache.catalina.startup.HostConfig deployWAR
SEVERE: Error deploying web application archive /Applications/tomcat7/webapps/InterswitchVerveMobile.war
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/InterswitchVerveMobile]]
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1022)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:994)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1127)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:2020)
    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:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

Jun 07, 2019 11:53:54 AM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deployment of web application archive /Applications/tomcat7/webapps/InterswitchVerveMobile.war has finished in 323 ms

我使用 ./gradlew dependencies > deps.txt 将 gradle 依赖项保存在一个文件中,内容可以在 github 要点 https://gist.github.com/Phainix/31aa9b95232e6394c95f97fabdc94c79

中找到

如有任何帮助,我将不胜感激

也许你应该改变

compileOnly("org.springframework.boot:spring-boot-starter-tomcat:1.5.21.RELEASE")

providedRuntime "org.springframework.boot:spring-boot-starter-tomcat:1.5.21.RELEASE"

它是一个依赖项,我认为不应该在 war-File 中。