[web教学] Unable to start web server; nested exception is org.springframework.c

[复制链接]
查看739 | 回复0 | 2023-8-23 12:01:37 | 显示全部楼层 |阅读模式 来自 中国北京
SpringBoot项目启动报错,如图

Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.这个错误
可以看出ServletWebServerFactory在sping容器启动时没有将其注册进去,缺少相干依赖。没有对应的servelt容器,工程当然也就启动不起来。这里多讲一下,springboot工程会通过@EnableAutoConfiguration这个注解去拉去默认配置,该注解通过@Import注解导入了AutoConfigurationImportSelector类。实在这个类,就是导入通过加载配置文件,加载了很多工厂方法的配置类。最终会加载 META-INF/spring.factories这些文件,通过这些文件完成主动装配。@Import注解加载了tomcat,jetty,undertow三个web服务器的配置类。由于没有导入jetty和undertow的相干jar包,这两个类实例的不会真正的加载。到这里分析,为什么会缺少相应的servlet容器?springboot不默认加载了tomcat容器吗,因为tomcat的相干jar包已经在spring-boot-starter-web中引入了,按照之前我们的分析,现实上被加载的容器应该是tomcat,为什么还会找不到呢?
以是在项目里找spring-boot-starter-tomcat这个依赖,发现没有。。。。。
竟然没有!
手动添加
  1.         <dependency>
  2.                 <groupId>org.springframework.boot</groupId>
  3.                 <artifactId>spring-boot-starter-tomcat</artifactId>
  4.                 <version>2.1.5.RELEASE</version>
  5.         </dependency>
复制代码
重新运行,可以了
当然还有各种其他问题也会导致没有注册到容器中,得自己一一排查

来源:https://blog.csdn.net/qq_42875600/article/details/130176394
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则