Spring Boot + Tomcat + Jetty - Application failed to start

Viewed 612

I am using Spring Boot + Java 8. Added a REST resource and trying to test to make sure the basic configs are correct.

But I am facing an issue while starting the Spring Boot application. Please find the below logs.

021-01-15 00:19:53.320  WARN 22065 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is java.lang.NoSuchMethodError: org.apache.tomcat.util.ExceptionUtils.preload()V
2021-01-15 00:19:53.329  INFO 22065 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-01-15 00:19:53.347 ERROR 22065 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    org.apache.catalina.startup.Tomcat.<init>(Tomcat.java:183)

The following method did not exist:

    org.apache.tomcat.util.ExceptionUtils.preload()V

The method's class, org.apache.tomcat.util.ExceptionUtils, is available from the following locations:

    jar:file:/home/xyz/.gradle/caches/modules-2/files-2.1/org.eclipse.jetty/jetty-runner/9.3.20.v20170531/56d1d067b4e42a6c603ece754534f9a65211924a/jetty-runner-9.3.20.v20170531.jar!/org/apache/tomcat/util/ExceptionUtils.class
    jar:file:/home/xyz/.gradle/caches/modules-2/files-2.1/org.apache.tomcat.embed/tomcat-embed-core/9.0.41/a43e9711e85073187d04b137882b4b7957180ef0/tomcat-embed-core-9.0.41.jar!/org/apache/tomcat/util/ExceptionUtils.class

The class hierarchy was loaded from the following locations:

    org.apache.tomcat.util.ExceptionUtils: file:/home/xyz/.gradle/caches/modules-2/files-2.1/org.eclipse.jetty/jetty-runner/9.3.20.v20170531/56d1d067b4e42a6c603ece754534f9a65211924a/jetty-runner-9.3.20.v20170531.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of org.apache.tomcat.util.ExceptionUtils

I tried excluding tomcat and still got the same issue.

Please look into my Gradle settings below.

plugins {
    id 'org.springframework.boot' version '2.4.1'
    id 'io.spring.dependency-management' version '1.0.10.RELEASE'
    id 'java'
}

group = 'com.hive'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
targetCompatibility = '1.8'

configurations {
    all*.exclude module: 'log4j'
    all*.exclude module: 'log4j-core'
    all*.exclude module: 'slf4j-log4j12'
    all*.exclude module: 'log4j-slf4j-impl'
}

repositories {
    mavenCentral()
}

dependencies {

    compile group: 'org.apache.commons', name: 'commons-dbcp2', version: '2.7.0'
    compile group: 'org.apache.hive', name: 'hive-jdbc', version: '3.1.2'

    compile group: 'org.springframework.boot', name: 'spring-boot-starter-web'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc'

    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

test {
    useJUnitPlatform()
}

Please suggest me some solution to solve the above dependency issue.

2 Answers

The issue is with hive-jdbc driver which downloads the jetty-runner where the dependency conflicts happened.

When excluded the jetty-runner from hive-jdbc, the above conflict issue got resolved.

    compile(group: 'org.apache.hive', name: 'hive-jdbc', version: '3.1.2') {
        exclude(group: 'org.eclipse.jetty', module: 'jetty-runner')
    }

I think maybe this is because you have not added the gradle plugin to your build, you can do it by:

plugins {
id "org.springframework.boot" version "2.0.1.RELEASE"
}

If you're using a Gradle version earlier than 2.1 or you need dynamic configuration, you can add it like this instead:

buildscript {
ext {
    springBootVersion = '2.0.1.RELEASE'
}
repositories {
    mavenCentral()
}
dependencies {
    classpath(
      "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}

apply plugin: 'org.springframework.boot'

Let me know if this works.

Related