Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServer

时间:2024-05-23 12:43:04
问题:
Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.


Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServer


原代码:

SpringbootDemoApplication启动类:

@SpringBootApplication
public class SpringbootDemoApplication {

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

HelloController类:

@RestController
public class HelloController {

   @RequestMapping(value = "sayhello", method = RequestMethod.GET)
   public String sayhello() {
      return "Hello SpringBoot !";
   }
}


解决方案:

HelloController加上注解@EnableAutoConfiguration即可。

运行结果:

Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServer