gpt4 book ai didi

java - Spring Boot : java. lang.IllegalArgumentException:找到多个名为 [spring_web] 的片段

转载 作者:行者123 更新时间:2023-12-02 01:20:58 37 4
gpt4 key购买 nike

我在 tomcat 9 上部署 Spring Boot War 时得到了这个。我尝试了很多解决方案,例如清理项目以及我在 stackoverflow 中找到的所有可能的解决方案,但没有任何效果,其中之一是在 web.xml 中提供绝对排序,但它是一个 Spring Boot 应用程序,所以我不需要使用 web.xml 文件。该应用程序一直与本地主机完美配合,当我在服务器上部署 war 文件时出现问题。下面是错误。

    23-Aug-2019 04:03:25.139 INFO [Catalina-utility-2] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [/opt/apache-tomcat/webapps/LoopServer.war]
23-Aug-2019 04:03:27.100 SEVERE [Catalina-utility-2] org.apache.catalina.startup.HostConfig.deployWAR Error deploying web application archive [/opt/apache-tomcat/webapps/LoopServer.war]
java.lang.IllegalStateException: Error starting child
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:716)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:690)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:695)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:978)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1849)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112)
at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:773)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:427)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1620)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:305)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1144)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1346)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1350)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1328)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/LoopServer]]
at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:713)
... 25 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:2257)
at org.apache.tomcat.util.descriptor.web.WebXml.orderWebFragments(WebXml.java:2215)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1127)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:768)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:301)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5048)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
... 26 more

23-Aug-2019 04:03:27.103 INFO [Catalina-utility-2] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/opt/apache-tomcat/webapps/LoopServer.war] has finished in [1,964] ms

下面是我的 gradle 依赖配置

group 'com.lss.loopserver'
version '1.0-SNAPSHOT'
buildscript {
ext {
springBootVersion = '2.1.2.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("javax.servlet:javax.servlet-api:4.0.1")
}
}

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

war {
baseName = 'LoopServer'
version = '0.0.1'
}

sourceCompatibility = 1.8

repositories {
mavenCentral()
jcenter()
maven { url "http://repo.spring.io/libs-snapshot" }
}
configurations {
providedRuntime
compile.exclude module: 'spring-boot-starter-tomcat'
all*.exclude module: 'spring-boot-starter-logging'
}

dependencies {
testImplementation group: 'junit', name: 'junit', version: '4.12'
implementation('org.springframework.boot:spring-boot-starter-actuator')
implementation('org.springframework.boot:spring-boot-starter-data-jpa') {
exclude group: 'com.zaxxer', module: 'HikariCP'
}
implementation('org.springframework.cloud:spring-cloud-starter-oauth2')
implementation('org.springframework.boot:spring-boot-starter-security') {
exclude group: 'org.springframework', module: 'spring-aop'
}
implementation('org.springframework.boot:spring-boot-starter-aop')
implementation("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
}
providedCompile('javax.servlet:javax.servlet-api:4.0.1')

compile('javax.el:javax.el-api:3.0.0')
compile('javax.validation:validation-api:2.0.1.Final')
compile('org.hibernate:hibernate-validator:5.4.1.Final')
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
implementation('javax.inject:javax.inject:1')
implementation('mysql:mysql-connector-java:6.0.6')
implementation('joda-time:joda-time:2.10.2')
implementation ('com.google.code.gson:gson:2.8.1')
implementation group: 'commons-fileupload', name: 'commons-fileupload', version: '1.3.3'
implementation ('org.apache.commons:commons-io:1.3.2')
runtime('org.springframework.boot:spring-boot-devtools')
runtime('com.h2database:h2')
testImplementation('org.springframework.boot:spring-boot-starter-test')
}

dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:Greenwich.RC2"
}
}

bootRun {
sourceResources sourceSets.main
}

application.yml:

server:
port: 8080
servlet:
context-path: /LoopServer
spring:
datasource:
url: jdbc:mysql://${db.host:localhost}:${db.port:3306}/${db.name:loopschool}?useSSL=false
username: ${db.uid:root}
password: ${db.pwd:password}
driver-class-name: com.mysql.cj.jdbc.Driver
tomcat:
test-while-idle: true
validation-query: SELECT 1
type: com.mysql.cj.jdbc.MysqlDataSource
jpa:
properties:
hibernate:
dialect: org.hibernate.dialect.MySQL5Dialect
id:
new_generator_mappings: false
format_sql: true
hibernate:
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
ddl-auto: validate
open-in-view: false
application:
name: LoopServer
jmx:
default-domain: LoopServer
main:
allow-bean-definition-overriding: true
devtools:
livereload:
enabled: false
logging:
level:
org:
hibernate:
SQL: DEBUG
type:
descriptor:
sql:
BasicBinder: TRACE

主类:

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication
public class Main extends SpringBootServletInitializer {

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Main.class);
}

public static void main(String[] args) {

SpringApplication.run(Main.class, args);
}
}

如果有人知道有关该错误的任何想法,请帮助我。

最佳答案

清理服务器(在我的例子中是tomcat)或者删除 tomcat 服务器和工件 ID。再次配置即可正常工作

关于java - Spring Boot : java. lang.IllegalArgumentException:找到多个名为 [spring_web] 的片段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57626140/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com