I encountered this error when I tried to deployed war in tomcat with spring boot 2.1.2.My tomcat version is 8.5.14 and java is 1.8.0_121.I think i had done everything right and its working perfectly in my machine but its not working when i deploy it on server with below error.

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

Below is my build.gradle config

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
}

The Application class with main function as below.

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

1 Answers

0
Yugansh On

NoSuchMethodError error, the most likely is the problem of the introduction of the jar package, or the jar package conflict.

You can look at the tree structure of the jar package through maven and see the dependencies after the jar package. If it is true that the jar package is missing, import the jar package, for example, Caused by: java.lang.NoSuchMethodError: org.springframework.aop.xxxxx.xxxxx. I will first look for the jar package that the project depends on. There is no such jar package exists, and then there is no such class, the method.

If not, you can add dependencies via the pom (maven configuration file) file. If this class exists, it is likely that the jar package conflicts. For a jar package conflict, let's take a very simple example. If you reference the A.jar package and the B.jar package, both A and B depend on the C.jar package. However, A depends on the 1.1 version of the C.jar package, and B depends on the 2.1 version of the jar package. If your project is stored in version 1.1 at this time, it is very likely that an error will be reported.

Seems there is a dependency exclusion you should do ,

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>

Refer the dependency sections of spring boot repos , seems to be transitive dependency issue 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"
    }