SpringBoot 启动报错 “Unable to start ServletWebServerApplicationContext due to missing ServletWebServerF

野性酷女 2023-10-12 17:28 155阅读 0赞

项目报错信息:

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzQ2NDA1NTg5_size_16_color_FFFFFF_t_70

  1. 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.
  2. at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:
  3. 156) ~[spring-boot-
  4. 2.2
  5. .2.RELEASE.jar:
  6. 2.2
  7. .2.RELEASE]
  8. at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:
  9. 544) ~[spring-context-
  10. 5.2
  11. .2.RELEASE.jar:
  12. 5.2
  13. .2.RELEASE]
  14. at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:
  15. 141) ~[spring-boot-
  16. 2.2
  17. .2.RELEASE.jar:
  18. 2.2
  19. .2.RELEASE]
  20. at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:
  21. 747) ~[spring-boot-
  22. 2.2
  23. .2.RELEASE.jar:
  24. 2.2
  25. .2.RELEASE]
  26. at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:
  27. 397) ~[spring-boot-
  28. 2.2
  29. .2.RELEASE.jar:
  30. 2.2
  31. .2.RELEASE]
  32. at org.springframework.boot.SpringApplication.run(SpringApplication.java:
  33. 315) ~[spring-boot-
  34. 2.2
  35. .2.RELEASE.jar:
  36. 2.2
  37. .2.RELEASE]
  38. at org.springframework.boot.SpringApplication.run(SpringApplication.java:
  39. 1226) ~[spring-boot-
  40. 2.2
  41. .2.RELEASE.jar:
  42. 2.2
  43. .2.RELEASE]
  44. at org.springframework.boot.SpringApplication.run(SpringApplication.java:
  45. 1215) ~[spring-boot-
  46. 2.2
  47. .2.RELEASE.jar:
  48. 2.2
  49. .2.RELEASE]
  50. at com.atguigu.yygh.gateway.ServerGatewayApplication.main(ServerGatewayApplication.java:
  51. 11) ~[classes/:na]
  52. Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
  53. at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getWebServerFactory(ServletWebServerApplicationContext.java:
  54. 203) ~[spring-boot-
  55. 2.2
  56. .2.RELEASE.jar:
  57. 2.2
  58. .2.RELEASE]
  59. at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:
  60. 179) ~[spring-boot-
  61. 2.2
  62. .2.RELEASE.jar:
  63. 2.2
  64. .2.RELEASE]
  65. at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:
  66. 153) ~[spring-boot-
  67. 2.2
  68. .2.RELEASE.jar:
  69. 2.2
  70. .2.RELEASE]
  71. ...
  72. 8 common frames omitted
  73. Process finished with exit code
  74. 1

解决方法:

1,检查入口 Application 文件是否加了 @SpringBootApplication 注解,或者 @SpringBootConfiguration、@EnableAutoConfiguration 两个注解

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzQ2NDA1NTg5_size_16_color_FFFFFF_t_70 1

2,检查 pom.xml 是否正确添加 web 依赖:

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzQ2NDA1NTg5_size_16_color_FFFFFF_t_70 2

3、在启动类中,.class的名称要与启动类名称相同(低级错误,本人就是这个错误。在编码时候使用了idea的自动补全功能,导致这个低级错误的出现!)

错误实例:

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzQ2NDA1NTg5_size_16_color_FFFFFF_t_70 3

正确实例:

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzQ2NDA1NTg5_size_16_color_FFFFFF_t_70 4

这真是一个很低级的错误,从这个错误中,可以反思进一步论证出: 编程是一项技术活儿和精细活儿,不论自身技术到了什么程度,都应该注意最基本的细节,否则会白白耗费自己大量的时间。

特此记录。

发表评论

表情:
评论列表 (有 0 条评论,155人围观)

还没有评论,来说两句吧...

相关阅读