Nicht starten ServletWebServerApplicationContext aufgrund fehlender ServletWebServerFactory bean

Wenn ich die Anwendung mit main-Anwendung, ich habe den Fehler in consoleUnable zu starten web-server; verschachtelte Ausnahme ist org.springframework.Kontext.ApplicationContextException: Unable to start ServletWebServerApplicationContext aufgrund fehlender ServletWebServerFactory bean.

Hauptanwendung

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

Servlet Initialisierung -

public class ServletInitializer extends SpringBootServletInitializer {

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

bauen.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'
}

Mir Helfen

Vermutlich verursacht durch die providedRuntime Umfang der Abhängigkeit sehen, wenn es zu verändern compile hilft.
thanq seine Werke für mich
Ich hatte das gleiche Problem und festgestellt, dass die Zugabe spring-boot-starter-web hat den trick. Ich habe nicht die tomcat-starter überhaupt. Ich bin mit der version 2.0.0.M7, also vielleicht ist das der Unterschied.
Ich bin immer der Fehler, kann ich ihn beheben kann durch entfernen des tomcat Ausgrenzung, die Hinzugefügt wurde, in einem Versuch zu verwenden Steg statt, aber wenn ich verwenden möchten, jetty, wie man den Fehler beheben?
tomcat-starter kann gezogen werden, von einer anderen Abhängigkeit, in meinem Fall ist es eine transitive Abhängigkeit von spring-boot-starter-web-services.

InformationsquelleAutor Vinay | 2017-09-28

Schreibe einen Kommentar