记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 ...
随机推荐
- c++基础之变量和基本类型
之前我写过一系列的c/c++ 从汇编上解释它如何实现的博文.从汇编层面上看,确实c/c++的执行过程很清晰,甚至有的地方可以做相关优化.而c++有的地方就只是一个语法糖,或者说并没有转化到汇编中,而是 ...
- border多层渐变
.content { margin-top: 19px; border-top: 1px dashed rgba(113, 183, 248, 0.6) !important; border-left ...
- C/C++ 实现Windows注册表操作
Windows注册表(Registry)是Windows操作系统中用于存储系统配置信息.用户设置和应用程序数据的一个集中式数据库.它是一个层次结构的数据库,由键(Key)和值(Value)组成,这些键 ...
- Oracle 数据库锁表问题及相关解决方法
Oracle 数据库锁表问题及相关解决方法 问题描述: 今天在公司运行服务的时候,需要查询300多万的数据,再进行排序之后放到kafka的消息队列中,供flink进行消费.在服务器上直接运行后,服务报 ...
- IntPtr 来把指针转换为 Int
由于想得到指针的值,这个时候,不能把指针强制转换为 integer 因为 integer 只适合32位的系统,64位的系统下,需要用 int64, 通过这个函数来转换,就可以屏蔽掉系统是32位 还是 ...
- CF-926(已更新:B)
CF-926 两点睡,七点起,阎王夸我好身体-- 主要这场实在是难绷,两个小时都在C题上吊死了,也不是没想过跳题,只是后面的题我更是一点思路都没有-^- "就喜欢这种被揭穿的感觉,爽!&qu ...
- NC16810 [NOIP1999]拦截导弹
题目链接 题目 题目描述 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能高于前一发的高度.某天,雷达 ...
- 轻松玩转makefile | 变量与模式
前言 本文通过简单的几个示例,以及对同一个Makefile进行几个版本的迭代,帮助快速的理解变量和模式规则的使用. 1.回顾 在上一篇文章中,我们使用Makefile编译fun.c和main.c这两个 ...
- java zTree异步加载实战
zTree简介 zTree 是一个依靠 jQuery 实现的多功能 "树插件".优异的性能.灵活的配置.多种功能的组合是 zTree 最大优点. zTree 是开源免费的软件(MI ...
- Java集合框架学习(三) TreeSet详解
TreeSet介绍 1.TreeSet是SortedSet接口的唯一实现类,TreeSet可以确保集合元素处于排序状态. 2.向TreeSet中加入的应该是同一个类的对象. 3.TreeSet判断两个 ...