@SpringBootApplication
をつけずに実行するとこの例外がスローされる。
//@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]
メッセージが示すようにServletWebServerFactory
beanが何らかの要因でcontext上にロードされていないとこのエラーになる。spring-bootの場合はautoconfigに頼ってれば、@SpringBootApplication
を付け忘れとかの凡ミスを除けば、問題ない。それ以外の場合は手作業でbeanを登録してやることになるかと。