今天拉下了一个新的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.问题处理的更多相关文章

  1. 【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 ...

  2. spring Boot 出现:org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.

    org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplication ...

  3. 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 ...

  4. nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.报错解决

    近期在学springboot,学的时候遇到这个错,网上查了好多,改了不行,后来发现自己的配置类没有加@SpringBootApplication注解 Exception encountered dur ...

  5. 解决问题:Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.

    Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean. 注释掉, ...

  6. Spring boot 报错 Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.

    在实际开发中修改别人的代码,发现了这个报错,后来发现是因为pom.xml里面 只要将注释掉的部分注释掉就好了.

  7. springboot 运行出现错误 Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.

    原因是我将springboot启动类换到了另外一个方法中 出现了一个异常 后来发现因为我换了类但是忘记了换类名所以才报错 @ComponentScan @EnableAutoConfiguration ...

  8. Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean

    WebsocketSourceConfiguration { @Bean ServletWebServerFactory servletWebServerFactory(){ return new T ...

  9. 解决spring-boot启动异常Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean

    第一种: 需要在主类头加上  @EnableAutoConfiguration 第二种: pom文件是否加了 <dependency> <groupId>org.mybatis ...

  10. 【转载】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 ...

随机推荐

  1. 深入理解TF-IDF、BM25算法与BM25变种:揭秘信息检索的核心原理与应用

    深入理解TF-IDF.BM25算法与BM25变种:揭秘信息检索的核心原理与应用 1.文本特征表示方法: TF-IDF 在信息检索, 文本挖掘和自然语言处理领域, IF-IDF 这个名字, 从它在 20 ...

  2. 3.1 DLL注入:常规远程线程注入

    动态链接库注入技术是一种特殊的技术,它允许在运行的进程中注入DLL动态链接库,从而改变目标进程的行为.DLL注入的实现方式有许多,典型的实现方式为远程线程注入,该注入方式的注入原理是利用了Window ...

  3. 基于SpringBoot应⽤的logback⽇志配置

    SpringBoot默认整合了logback-classic⽇志框架,我们需要对logback⽇志框架进⾏配置 以⾃定义⽇志输出格式.⽇志⽂件配置.⽇志⽂件保存策略等信息 <?xml versi ...

  4. P4747 [CERC2017] Intrinsic Interval 题解

    题目链接:Intrinsic Interval 讲讲析合树如何解决这种问题,其实这题很接近析合树的板题的应用. 增量法进行析合树建树时,需要用 ST 表预处理出 \(max\) 和 \(min\) 以 ...

  5. (C语言)关于printf的新发现: 可以用字符串变量替代第一个字符串参数

    char a[] = "hello%d\n%dworld"; printf(a, 2, 3); //输出: //hello2 //2world 事情的起因是使用printf(&qu ...

  6. Java应用系统监控方法简介

    1. tsar 阿里巴巴开源的实时系统监控工具.其内部的sunfire有部分指标就是基于该工具每分钟采集一次来获取的. github 监控项及数据来源一览 摘自tsar/info.md 监控项 来源 ...

  7. JAVA入门学习之GUI编程思想——day01

    GUI编程 什么是GUI???图形化编程 组件 窗口 弹窗 按钮 文本框 图片 事件 ..... GUI的核心:AWT Swing GUI编程的缺陷: ​ 1.界面不美观 ​ 2.需要jre环境 虽然 ...

  8. 《ASP.NET Core 微服务实战》-- 读书笔记(第1章 、第2章)

    译者序 微服务设计方法清晰定义了各个开发团队的业务边界,微服务框架以不同方式实现了服务之间的协作与集成. .NET Core 作为全新的 .NET 技术,它不仅完全开源.跨平台,更面向云原生开发进行了 ...

  9. Nodepad++格式化XML和JSON字符串

    (一)格式化XML 1.安装XML Tools 在notepad++中点击菜单栏[插件]-[插件管理]. 在插件管理界面选择[XML Tools],点击[安装]. 2.打开XML文件 在notepad ...

  10. Linux-CentOS7登录页面出现Hint: caps lock on,输入大小写字母反了(大小写反转问题)

    问题描述:虚拟机CentOS7,输入大小写字母反了,开启capslock的时候变成小写字母了,关闭则变成大写了... 解决办法:只需要执行:setleds +caps 或 setleds -caps  ...