Unable to start web server; nested exception is org.springframework.context.ApplicationContextExcept

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这个依赖,发现没有。。。。。
竟然没有!

手动添加

	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-tomcat</artifactId>
		<version>2.1.5.RELEASE</version>
	</dependency>

重新运行,可以了

当然还有各种其他问题也会导致没有注册到容器中,得自己一一排查

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Unable to start web server; nested exception is org.springframework.context.ApplicationContextException是由于缺少ServletWebServerFactory bean引起的。这个问题通常是因为在启动类中没有正确配置注解导致的。解决方法是在启动类之前添加@EnableAutoConfiguration注解。同时,确保Controller类已经正确配置了@Controller注解,并且在主程序中使用@SpringBootApplication注解进行配置。下面是一个修正后的示例代码: ```java @EnableAutoConfiguration @Controller public class HelloController { @ResponseBody @RequestMapping("/hello") public String hello(){ return "hello SpringBoot!"; } } ``` 主程序: ```java @SpringBootApplication public class HelloApplication { public static void main(String[] args) throws Exception { SpringApplication.run(HelloController.class, args); } } ``` 这样,应该就能够解决Unable to start web server的问题了。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [SpringBoot报错:Unable to start web ... nested exception is org.springframework.context.Application](https://blog.csdn.net/dl962454/article/details/105881089)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [解决Handler processing failed; nested exception is java.lang.NoClassDefFoundError_kmode exception](https://download.csdn.net/download/lj_70596/14122358)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值