记spring boot启动出现Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.问题处理
今天拉下了一个新的springboot工程,启动时出现了Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.这个异常。在网上搜索这个错误,有几种说法。
说法一:是因为缺少一个spring-boot-starter-web依赖。检查pom文件,发现这个依赖已经被引入了,所以不是这个问题。
说法二:是没有添加@EnableAutoConfiguration这个注解。但是在启动类中已经有@SpringBootApplication这个注解了,这个注解已经包含了@EnableAutoConfiguration注解,所以也不是这个原因,那么到底是什么原因呢。
检查异常发生地点

点进去抛出异常的代码

可见是在调用getWebServerFactory()方法时候发生错误,没有找到ServletWebServerFactory这个bean,说明在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,为什么还会找不到呢?
那么此时我们要分析一下整个工程的依赖情况,看tomcat相关jar包是否被真实的引入。使用mvn dependency:tree命令,对工程进行依赖分析,定位到tomcat相关依赖。

此时可以发现,tomcat相关依赖的scope类型是provied的,provide类型不会只会参与编译和测试,并不会参与运行,所以在工程启动运行是找不到相关依赖,所以就会报错。

将pom中的<scope>provided</scope>或者整个依赖注释掉,默认的scope类型是compile,参与编译测试和运行。重新启动工程,启动OK。
参考文章:
https://blog.csdn.net/qq_29551611/article/details/119268637
https://baijiahao.baidu.com/s?id=1719114849179396100&wfr=spider&for=pc
记spring boot启动出现Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.问题处理的更多相关文章
- 【spring boot】整合LCN,启动spring boot2.0.3 启动报错:Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
spring boot 2.0.3启动报错: Error starting ApplicationContext. To display the conditions report re-run yo ...
- spring Boot 出现:org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplication ...
- Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
SpringBoot启动时的异常信息如下: "C:\Program Files\Java\jdk1.8.0_161\bin\java" ......... com.fangxing ...
- nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.报错解决
近期在学springboot,学的时候遇到这个错,网上查了好多,改了不行,后来发现自己的配置类没有加@SpringBootApplication注解 Exception encountered dur ...
- 解决问题:Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean. 注释掉, ...
- Spring boot 报错 Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
在实际开发中修改别人的代码,发现了这个报错,后来发现是因为pom.xml里面 只要将注释掉的部分注释掉就好了.
- springboot 运行出现错误 Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
原因是我将springboot启动类换到了另外一个方法中 出现了一个异常 后来发现因为我换了类但是忘记了换类名所以才报错 @ComponentScan @EnableAutoConfiguration ...
- Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean
WebsocketSourceConfiguration { @Bean ServletWebServerFactory servletWebServerFactory(){ return new T ...
- 解决spring-boot启动异常Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean
第一种: 需要在主类头加上 @EnableAutoConfiguration 第二种: pom文件是否加了 <dependency> <groupId>org.mybatis ...
- 【转载】springboot启动报错(Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWe)
SpringBoot启动时的异常信息如下: 1 "C:\Program Files\Java\jdk1.8.0_161\bin\java" ......... com.fangxi ...
随机推荐
- CentOS7设置防火墙
①查看防火状态 systemctl status firewalld service iptables status ②暂时关闭防火墙 systemctl stop firewalld service ...
- RabbitMQ高级知识(消息可靠性,死信交换机,惰性队列,MQ集群)
服务异步通信-高级篇 消息队列在使用过程中,面临着很多实际问题需要思考: 1.消息可靠性 消息从发送,到消费者接收,会经历多个过程: 其中的每一步都可能导致消息丢失,常见的丢失原因包括: 发送时丢失: ...
- 【双指针】双指针算法详解两道经典OJ【力扣27,力扣26,力扣38】超详细算法教程
[双指针]双指针算法详解两道经典OJ[力扣27,力扣26,力扣38]超详细算法教程 今天又又到了我们刷力扣题的时间啦! 今天博主给大家带来的三道题是: 27. 移除元素 26. 删除有序数组中的重复项 ...
- Java开发学习(四十七)----MyBatisPlus删除语句之多记录操作
1.多记录操作 先来看下问题: 之前添加了很多商品到购物车,过了几天发现这些东西又不想要了,该怎么办呢? 很简单删除掉,但是一个个删除的话还是比较慢和费事的,所以一般会给用户一个批量操作,也就是前面有 ...
- 记忆化搜索 P1028 数的计算
P1028 [NOIP2001 普及组] 数的计算 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) 一开始是想暴力搜索的,也就是枚举比n/2小的数,但是只过了5个点,其他点都TLE ...
- XD刷机中执行reclaimdisks.sh的作用
之前刷机提到在使用OEDA进行一键部署前,需先在所有DB节点上运行reclaimdisks.sh,也提到观察会释放pvs/vgs/lvs相对应的剩余空间. 本文以一套X8环境为例,来看下具体的表现,以 ...
- Java-将文本(字符串)转化成二进制字符
今天在测试MySQL的Blob相关类型时,这种一般存放的是二进制文本,所以就想插入二进制文本. package com.aaa.dao; public class aaa { public stati ...
- [Spring]Junit单元测试时取不到本地文件问题
Junit单元测试时取不到本地文件问题 问题 当使用Junit进行单元测试时,遇到了以下问题: 2022-10-24 16:13:19.902 [main] ERROR zonetop.gisboot ...
- 好书推荐之《Java 核心技术:卷 1 基础知识》
大佬推荐 <Java 核心技术:卷 1 基础知识>,这本书本来是 Sun 公司的官方用书,是一本 Java 的入门参考书. 对于 Java 初学者来说,是一本非常不错的值得时常翻阅的技术手 ...
- DS1302与STC12的连接电路和驱动实现
简介 DS1302是低功耗带RAM的实时时钟电路, 常见的SOP8封装体积很小, 它可以对年月日周时分秒进行计时, 具有闰年补偿功能, 工作电压为2.0V-5.5V, 采用三线接口与CPU进行同步通信 ...