[JAVA] Unable to start ServletWebServerApplicationContext without SpringBootApplication

This exception is thrown when run without @SpringBootApplication </ code>.

//@SpringBootApplication
public class App {
    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }
}
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.0.4.RELEASE.jar:2.0.4.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE]

As the message indicates, this error will occur if the ServletWebServerFactory bean is not loaded on the context for some reason. In the case of spring-boot, if you rely on autoconfig, there is no problem except for common mistakes such as forgetting to add @SpringBootApplication </ code>. In other cases, I wonder if I will manually register the bean.

Recommended Posts