记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 ...
随机推荐
- fbx查看软件
对于3D的模型资源,比如fbx文件,除了使用专业的软件查看外,比如Unity3D,vs2015及更高版本,maya,3DMax等等,有没有更加轻量的软件可以查看fbx的内容呢? win10自带 win ...
- vue下载本地文件 下载二进制流文件 兼容ie
vue-cli2要下载的静态文件放在static目录下,vue-cli3则放在public目录下 ie不支持 h5 的download写法,故用以下写法 <el-button type=&quo ...
- P4402 [Cerc2007] robotic sort 机械排序题解
题目链接:[Cerc2007] robotic sort 机械排序 前置知识点:文艺平衡树 具体的我们会将序号下标作为平衡树的键值,这样一来每个节点其实就是数组中的每个位置,又因为这个位置是具有有序性 ...
- Redis有哪些潜在的慢操作?
Redis作为内存数据库,访问速度快是最大的特点,那么,什么情况下,Redis也会变慢呢? Redis底层数据结构 Redis有5种基本数据类型:String,List,Hash,Set,ZSet 有 ...
- 零基础入门Vue之窥探大法——计算与侦听
前言 在 上一小节 我介绍了我学习vue入门 插值语法 的过程. 在本篇,我将记录我对vue的 计算属性和侦听器 的学习记录 注:本篇对于"侦听"和"监听"是一 ...
- .NET Core开发实战(第9课:命令行配置提供程序)--学习笔记
09 | 命令行配置提供程序:最简单快捷的配置注入方法 这一节讲解如何使用命令行参数来作为配置数据源 命令行配置(提供程序的)支持三种格式的命令 1.无前缀的 key=value 模式 2.双中横线模 ...
- Java-获取当前时间并进行格式化
获取年月日 时分秒 import java.text.SimpleDateFormat; import java.util.Date; Date dt = new Date(); SimpleDate ...
- push竟比concat快上数百倍?记一个concat在十万级数据引发的性能问题
壹 ❀ 引 公司产品一直在做企业项目研发工具,所以我们自己当然也会用自己的产品去管理公司大小项目,但在此之前,项目管理体验上一直存在一个卡顿问题.比如我刚登录上账号,在项目里随便到处点点到处跳转页面, ...
- 从零开始的react入门教程(十),快速上手react-redux,相对于redux它究竟简化了什么?
壹 ❀ 引 在前面两篇文章中,我们介绍了redux与context部分概念与基本用法,这里我们做个简单复习. redux属于应用数据流框架,主要用于应用状态的管理,比如react中的state.其数据 ...
- JLink OB相关的一些记录
使用 STM32F103 Bluepill 制作 JLink OB https://github.com/GCY/JLINK-ARM-OB https://stm32duinoforum.com/fo ...