11

When i run the application using main application, i got the error in consoleUnable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.

Main Application

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

Servlet Initializer

public class ServletInitializer extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }
}

build.gradle

    buildscript {
        ext {
            springBootVersion = '2.0.0.M4'
        }
        repositories {
            jcenter()
            mavenCentral()
            maven { url "https://repo.spring.io/snapshot" }
            maven { url "https://repo.spring.io/milestone" }
        }
        dependencies {
            classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        }
    }

    plugins {
        id "org.sonarqube" version "2.5"
    }

    apply plugin: 'java'
    apply plugin: 'idea'
    apply plugin: 'eclipse-wtp'
    apply plugin: 'jacoco'
    apply plugin: 'org.springframework.boot'
    apply plugin: 'io.spring.dependency-management'
    apply plugin: 'war'


    group = 'com.demo'
    version = '0.0.1-SNAPSHOT'

    // Uses JDK 8
    sourceCompatibility = 1.8
    targetCompatibility = 1.8

    repositories {
        maven { url "https://repo.spring.io/milestone" }
        jcenter()
        mavenCentral()
        maven { url "https://repo.spring.io/snapshot" }
    }
    configurations {
        providedRuntime
    }
    dependencies {

        // SPRING FRAMEWORK
        compile('org.springframework.boot:spring-boot-starter-web')
        compile('org.springframework.boot:spring-boot-starter-aop')
        compile('org.springframework.boot:spring-boot-starter-actuator')

        // Tomcat Server
        providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')

        //Spring Jpa
        compile('org.springframework.boot:spring-boot-starter-data-jpa')

        // SPRING SECURITY
        compile('org.springframework.boot:spring-boot-starter-security')

        // MYSQL and HIBERNATE
        compile 'mysql:mysql-connector-java:5.1.34'
        //compile 'org.hibernate:hibernate-core:5.2.11.Final'
        //compile 'org.hibernate:hibernate-validator:5.1.3.Final'
}

Help Me

Vinay
  • 123
  • 1
  • 1
  • 5
  • Probably caused by the `providedRuntime` scope of the dependency, see if changing it to `compile` helps. – CrazyCoder Sep 28 '17 at 09:14
  • @CrazyCoder thanq its works for me – Vinay Oct 03 '17 at 14:02
  • 1
    I had the same issue and found that adding spring-boot-starter-web did the trick. I don't have the tomcat starter at all. I'm using version 2.0.0.M7, so maybe that's the difference. – Chris Jan 19 '18 at 17:26
  • 1
    I'm getting the error, can I can fix it by removing the tomcat exclusion which was added in an attempt to use jetty instead, but if I want to use jetty, how to fix the error? – K.Nicholas Apr 03 '18 at 16:30
  • @Chris `tomcat-starter` may be pulled in by another dependency, in my case it's a transitive dependency of `spring-boot-starter-web-services`. – watery Nov 05 '18 at 13:00

0 Answers0