org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild:开始:org.apache.catalin

Posted

技术标签:

【中文标题】org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild:开始:org.apache.catalina.LifecycleException【英文标题】:org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start: org.apache.catalina.LifecycleException 【发布时间】:2019-09-26 07:22:25 【问题描述】:

当我尝试使用 spring boot 2.1.2 在 tomcat 中部署 war 时遇到此错误。我的 tomcat 版本是 8.5.14,java 是 1.8.0_121。我认为我做的一切都是正确的,它在我的机器上运行良好但是当我在服务器上部署它时出现以下错误,它不起作用。

08-May-2019 05:54:33.459 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.14
08-May-2019 05:54:33.462 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive /opt/apache-tomcat/webappsloop/LoopServer.war
08-May-2019 05:54:33.665 WARNING [localhost-startStop-1] org.apache.tomcat.util.descriptor.web.WebXml.setVersion Unknown version string [4.0]. Default version will be used.
08-May-2019 05:54:38.037 INFO [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
08-May-2019 05:54:38.041 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log 2 Spring WebApplicationInitializers detected on classpath
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/apache-tomcat/webappsloop/LoopServer/WEB-INF/lib/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/apache-tomcat/webappsloop/LoopServer/WEB-INF/lib/logback-classic-1.1.11.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
08-May-2019 05:54:38.231 SEVERE [localhost-startStop-1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start: 
 org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Loop].StandardHost[localhost].StandardContext[/LoopServer]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:952)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1823)
    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: Cannot instantiate interface org.springframework.boot.SpringApplicationRunListener : org.springframework.boot.context.event.EventPublishingRunListener
    at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:450)
    at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:429)
    at org.springframework.boot.SpringApplication.getRunListeners(SpringApplication.java:415)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:301)
    at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:157)
    at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:137)
    at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:91)
    at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:169)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5196)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 10 more
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.context.event.EventPublishingRunListener]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.aop.framework.AopProxyUtils.getSingletonTarget(Ljava/lang/Object;)Ljava/lang/Object;
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:184)
    at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:446)
    ... 19 more
Caused by: java.lang.NoSuchMethodError: org.springframework.aop.framework.AopProxyUtils.getSingletonTarget(Ljava/lang/Object;)Ljava/lang/Object;
    at org.springframework.context.event.AbstractApplicationEventMulticaster.addApplicationListener(AbstractApplicationEventMulticaster.java:109)
    at org.springframework.boot.context.event.EventPublishingRunListener.<init>(EventPublishingRunListener.java:58)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:172)
    ... 20 more

08-May-2019 05:54:38.232 SEVERE [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Error deploying web application archive /opt/apache-tomcat/webappsloop/LoopServer.war
 java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Loop].StandardHost[localhost].StandardContext[/LoopServer]]
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:756)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:952)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1823)
    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)

08-May-2019 05:54:38.232 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive /opt/apache-tomcat/webappsloop/LoopServer.war has finished in 4,770 ms

下面是我的 build.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")
    


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" 


dependencies 
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile('org.springframework.boot:spring-boot-starter-actuator')
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-security')
    compile('org.springframework.cloud:spring-cloud-starter-oauth2')
    compile 'org.springframework.boot:spring-boot-starter-aop'
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('javax.inject:javax.inject:1')
    compile ('mysql:mysql-connector-java:6.0.6')
    compile ('com.google.code.gson:gson:2.8.1')
    compile group: 'commons-fileupload', name: 'commons-fileupload', version: '1.3.3'
    compile 'org.apache.commons:commons-io:1.3.2'
    runtime('org.springframework.boot:spring-boot-devtools')
    runtime('com.h2database:h2')
    providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
    testCompile('org.springframework.boot:spring-boot-starter-test')


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


bootRun 
    sourceResources sourceSets.main

主要功能如下的Application类。

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

【问题讨论】:

请看一下,如果从本地到服务器(java 和 tomcat)有任何版本不匹配。密切关注 maven 或 gradle 中范围为“提供”或“测试”的任何依赖项。在此之后,完全清除您的编译目录(“target”或“out”)并在本地重建您的项目和任何工件并再次部署。 【参考方案1】:

NoSuchMethodError错误,最有可能是jar包引入的问题,或者jar包冲突。

可以通过maven查看jar包的树形结构,查看jar包后的依赖关系。如果确实缺少jar包,则导入jar包,例如Caused by: java.lang.NoSuchMethodError: org.springframework.aop.xxxxx.xxxxx。我会先找项目所依赖的jar包。没有这样的jar包存在,也就没有这样的类,方法。

如果没有,您可以通过 pom(maven 配置文件)文件添加依赖项。如果这个类存在,很有可能是jar包冲突。 对于jar包冲突,我们举一个很简单的例子。如果引用A.jar包和B.jar包,A和B都依赖C.jar包。但是A依赖1.1版本的C.jar包,B依赖2.1版本的jar包。如果你的项目此时存储在1.1版本,很有可能会报错。

似乎有一个你应该做的依赖排除,

For Gradle (but not sure):
    dependencies 
        implementation('org.springframework.boot:spring-boot-starter-security:version) 
            exclude group: 'org.springframework', module: 'spring-aop'
        
    
Maven way :
    <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId></artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-aop</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

参考spring boot repos的依赖部分,好像是传递依赖问题https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-aop/2.1.2.RELEASE

https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-security/2.1.2.RELEASE

Also for the Tomcat part
    dependencies 
        compile("org.springframework.boot:spring-boot-starter-web") 
            exclude module: "spring-boot-starter-tomcat"
        
        providedRuntime group: 'org.springframework.boot', name: 'spring-boot-starter-tomcat', version: "2.1.2.RELEASE"
    

【讨论】:

有同样的异常,或者gradle有问题?? ,尝试清理你的.m2(Spring-aop-folder),然后用旧代码重试,你应该可以在本地复制 同样的异常。本地tomcat服务器没有问题,它工作正常。当我在服务器上部署它时出现问题。 可能是 Tomcat 的问题,spring-boot-starter-web 有自己的 web,但似乎不太可能因为 AOP 发生错误

以上是关于org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild:开始:org.apache.catalin的主要内容,如果未能解决你的问题,请参考以下文章

org.apache.catalina.core.StandardContext startInternal SEVERE:错误 listenerStart

tomcat(11)org.apache.catalina.core.StandardWrapper源码剖析

idea tomcat 启动报错 org.apache.catalina.core.StandardService.initInternal Failed to initialize connecto

gradle问题“main”groovy.lang.MissingPropertyException:没有这样的属性:类的baseDir:org.apache.catalina.core.Standa

tomcat(12)org.apache.catalina.core.StandardContext源码剖析

org.apache.catalina.core.StandardWrapperValve invoke的解决办法