1

I have a spring boot app. It is mainly a Kafka listening app and its only web application part is the health check API through the spring-boot-starter-actuator. When running locally in IntelliJ, the application runs perfectly, with no errors and no crashes. However, when trying to run the app through docker, the app starts (i can see the spring logo) and then it imidietly crashes with the next error:

[org.springframework.boot.SpringApplication] - Application run failed 
MyApp    | 2021-02-25T19:17:17.802342316Z org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.

My dependency section in the build.gradle file looks as follows:

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    implementation 'org.springframework.kafka:spring-kafka'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.4.2'

    /*logging*/
    compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30'
    testCompile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.30'
    testCompile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
    compile group: 'net.logstash.logback', name: 'logstash-logback-encoder', version: '6.4'
    compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
    compile group: 'ch.qos.logback', name: 'logback-core', version: '1.2.3'
    compile group: 'ch.qos.logback', name: 'logback-access', version: '1.2.3'

    /*lombok*/
    compileOnly 'org.projectlombok:lombok:1.18.16'
    annotationProcessor 'org.projectlombok:lombok:1.18.16'

    /*metrics*/
    compile group: 'io.prometheus', name: 'simpleclient', version: '0.9.0'
    compile group: 'io.prometheus', name: 'simpleclient_httpserver', version: '0.9.0'
    compile group: 'io.prometheus', name: 'simpleclient_servlet', version: '0.9.0'
    compile group: 'io.micrometer', name: 'micrometer-registry-prometheus', version: '1.5.1'
    compile group: 'io.micrometer', name: 'micrometer-core', version: '1.5.1'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: '2.4.2'

    /*Jetty server*/
    compile group: 'org.eclipse.jetty', name: 'jetty-server', version: '9.4.29.v20200521'
    compile group: 'org.eclipse.jetty', name: 'jetty-servlet', version: '9.4.29.v20200521'

    /* mysql */
    compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.22'

    /*mongo*/
    compile group: 'org.mongodb', name: 'mongo-java-driver', version: '3.12.7'

    // generate pojo from avro schema
    compile "org.apache.avro:avro-compiler:1.10.0"

    //avro serde
    compile group: 'io.confluent', name: 'kafka-streams-avro-serde', version: '5.2.1'
    compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.12.0'
    compile group: 'io.projectreactor', name: 'reactor-core', version: '3.4.0'
    implementation('com.fasterxml.jackson.dataformat:jackson-dataformat-avro:2.11.2')

    /* cassandra*/
    implementation("io.dropwizard.metrics:metrics-core:3.2.2")
    compile group: 'com.datastax.cassandra', name: 'cassandra-driver-core', version: '3.8.0'
    compile group: 'com.datastax.cassandra', name: 'cassandra-driver-mapping', version: '3.10.2'

    /*tests*/
    testImplementation 'org.springframework.kafka:spring-kafka-test'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
    testCompile("junit:junit:4.12")
} 

My main application class looks as follows:

@SpringBootApplication()
public class MyApp {
    public static void main(String[] args) {
        SpringApplication.run(MyApp.class, args);
    }
}

Can anyone shed some light on the reason behind this issue and how to fix it? Why would it run with no problems in IntelliJ but crash with docker? Any help would be appreciated. Thank you.

Dan
  • 195
  • 2
  • 14
  • Possible duplicate? - docker is just a different environment you are running it in: https://stackoverflow.com/questions/50231736/applicationcontextexception-unable-to-start-servletwebserverapplicationcontext/50232382 – Martin Dallinger Feb 25 '21 at 20:23
  • Already tried every option in that post. Did not help. – Dan Feb 26 '21 at 09:37
  • @Dan were you able to solve this issue? In my case actuator somehow breaks Tomcat dependency :( – roseaysina Apr 26 '22 at 16:00

0 Answers0