Spring Boot : java.lang.IllegalArgumentException:

2019-08-28 01:58发布

I got this while deploying the spring boot war on tomcat 9.I have tried many solutions like cleaning project and every possible solution that i found in stackoverflow, But nothing worked, one of them are providing absolute ordering in web.xml, but its a spring boot application so i don't need to use a web.xml file.The application has been woorking perfectly with the localhost and problem comes when i deploy the war file on server.Below is the error.

    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

Below is my gradle dependency congiguration

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

Main class :

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);
    }
}

If anyone know any idea about the error please help me.

1条回答
戒情不戒烟
2楼-- · 2019-08-28 02:45

Finally i found some solution, it looks like there was some spring dependency conflicts was there.So what i was done is simple recreated the project with another name, then it started to work and the error also gone. Another possible solution is to clean your server in the right way(I haven't tried that, but i think it will work).

查看更多
登录 后发表回答