SpringBoot 报错 iniciar ServletWebServerApplicationContext debido a que falta el bean ServletWebServerFactory

El proyecto de los dos días anteriores no se subió a git, y hoy continué codificando el código y ocurrió un problema extraño.

¿Cómo puede ocurrir tal problema cuando el código no se ha movido durante dos días? Estoy muy deprimido. . . . . . . . . . . . . . . . . .

Problema: al iniciar un proyecto

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.
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:155) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:742) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:389) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:311) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1213) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1202) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
	at com.dataGovernance.DataGovernanceApplication.main(DataGovernanceApplication.java:14) [classes/:?]
Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getWebServerFactory(ServletWebServerApplicationContext.java:202) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:178) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:152) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
	... 8 more;

La pregunta anterior es obviamente: debido a que falta el bean ServletWebServerFactory
Pero, ¿por qué ocurre tal problema? ? ? ? ?
el código se muestra a continuación:

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

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(DataGovernanceApplication.class);
    }
}

pom.xml

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

Anote @SpringBootApplication, anotado;
herede la clase SpringBootServletInitializer y reescriba el método de configuración;
la dependencia del archivo pom también se importa;

También busqué mucho en Baidu. Básicamente, este problema son los tres problemas mencionados anteriormente.
También miré el código fuente de SpringBootServletInitializer, que era vago.

El último método que probé cambió el nombre de la clase de inicio y el nombre de método del método de inicio Lo extraño fue que el inicio fue exitoso y no se reportó ningún error. . . . . .
volverse

public class DataGovernanaceApplication extends SpringBootServletInitializer

Lo intenté unas cuantas veces más, pero no es suficiente modificar el nombre de la clase directamente. Primero modifique el nombre del método y luego modifique el tipo.

Debido a que el proyecto tiene prisa, solo podemos hacer este código primero y lo resolveremos más tarde.

Aquí todos, si saben cuál es el problema, explíquenlo, ¡muchas gracias! ! !

Supongo que te gusta

Origin blog.csdn.net/qq_41587243/article/details/105703092
Recomendado
Clasificación