【已解决】Spring容器中找不到ServletWebServerFactory类出现的异常

【已解决】ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean异常

概述

最近在运行一个springboot项目时,出现了下面的异常。

异常情况

具体异常如下所示

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:161) ~[spring-boot-2.3.5.RELEASE.jar:2.3.5.RELEASE]at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:545) ~[spring-context-5.2.10.RELEASE.jar:5.2.10.RELEASE]at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.5.RELEASE.jar:2.3.5.RELEASE]at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.5.RELEASE.jar:2.3.5.RELEASE]at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.5.RELEASE.jar:2.3.5.RELEASE]at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405) [spring-boot-2.3.5.RELEASE.jar:2.3.5.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.5.RELEASE.jar:2.3.5.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.5.RELEASE.jar:2.3.5.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.5.RELEASE.jar:2.3.5.RELEASE]at wiki.primo.dubbo.swagger.test.server.primodubboswaggertestserver.PrimoDubboSwaggerTestServerApplication.main(PrimoDubboSwaggerTestServerApplication.java:12) [classes/:na]
Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getWebServerFactory(ServletWebServerApplicationContext.java:205) ~[spring-boot-2.3.5.RELEASE.jar:2.3.5.RELEASE]at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:177) ~[spring-boot-2.3.5.RELEASE.jar:2.3.5.RELEASE]at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:158) ~[spring-boot-2.3.5.RELEASE.jar:2.3.5.RELEASE]... 9 common frames omitted

异常分析

这个异常情况有很多种,实际就是缺失了需要的类没有找到。

也就是在容器中没有注入ServletWebServerFactory类。

解决方案

这个异常可能有多个解决方案,因为有很多的原因。我先说说我用于解决问题的方案。

解决方案一

我是通过添加一个配置进行解决的。

在application.properties中可以进行添加:

spring.main.web-application-type=none

如果是yml文件,也就是 application.yml,可以添加:

  spring:main:web-application-type: none

这种处理方式可以在项目不是web项目的时候配置。

解决方案二

如果是springboot ,并且是web项目。那么检查一下是不是添加了@SpringBootApplication注解。

没有的话,加好就行了。

解决方案三

最后,可能就是缺失那个类了。检查一下依赖。

是不是有spring-boot-starter-web依赖了。

如果没有,那么在pom.xml文件中加好配置。

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId>
</dependency>

如果项目中用到了spring-boot-starter-webflux,也是使用的这种解决方案。

【已解决】Spring容器中找不到ServletWebServerFactory类出现的异常相关推荐

  1. 在普通类中获取spring容器中的bean

    在普通类中获取spring容器中的bean 1.工具类 package com.itheima.hchat.util;import org.springframework.beans.BeansExc ...

  2. Servlet自动注入Spring容器中的Bean解决方法

    Servlet自动注入Spring容器中的Bean解决方法 参考文章: (1)Servlet自动注入Spring容器中的Bean解决方法 (2)https://www.cnblogs.com/jank ...

  3. 解决无法注入spring容器,获取不到spring容器中的bean问题

    解决无法注入spring容器,获取不到spring容器中的bean问题 前两天工作中遇到一个问题,收到的需求是根据logbak日志实现通过过滤错误日志发送预警邮件到邮箱,logback自定义实现类如下 ...

  4. SpringBoot之Listener注册到Spring容器中的多种方法

    相关文章: SpringBoot 之AOP切面的使用 SpringBoot之Interceptor拦截器注入使用 SpringBoot之Filter过滤器的实现及排序问题 SpringBoot 之多个 ...

  5. Spring容器中获取Bean实例的七种方式(附实战源码)

    目录 写作说明 一:写作原因 二:源码出处 实现方式 一:使用BeanFactory直接获取(不推荐) 二:在初始化时保存ApplicationContext对象 三:继承自抽象类Applicatio ...

  6. boot spring 没有父子容器_理解 MyBatis 是如何在 Spring 容器中初始化的

    MyBatis 初始化过程就是 生成一些必须的对象放到 Spring 容器中 .问题是这个过程到底生成了哪些对象?当遇到 MyBatis 初始化失败时,如何正确的找到分析问题的切入点?本文将针对这些问 ...

  7. Spring容器中的Bean是否会被GC呢?

    Spring容器中的Bean是否会被GC呢?最近好几次被校招实习生问及,对于初学者来说,这应该是一个有意思的问题,鉴于此,笔者顺便写个这个文档. 1.Spring容器中Bean的作用域 当通过Spri ...

  8. 【已解决】ADT中通过Android SDK Manager去安装x86的image时无法下载

    [已解决]ADT中通过Android SDK Manager去安装x86的image时无法下载 [问题] 折腾: [已解决]ADT中调试Android项目但是无法打开对应的AVD即没有弹出对应的And ...

  9. Spring容器中获取 Bean 实例的七种方式

    点击关注公众号,利用碎片时间学习 说明 一.写作原因 首先解释一下写这篇博文的原因,因为在使用spring框架的过程中获取bean是非常常见的操作,但是网上非常的博文大多承自一家之言,因此很多可操作性 ...

最新文章

  1. 部署可扩展的目标检测管道:推理过程(上)
  2. 下属能否提拔,关键就看这10条!庸才是毒瘤,宁可错杀不可错用
  3. Nginx核心模块——HTTP中的配置指令location和rewrite介绍
  4. vue mianjs 引用css_vue 学习记录八——webpack中常见的配置项
  5. [Docker]Docker拉取,上传镜像到Harbor仓库
  6. ubuntu16.04 + kinetic +turtlebot2配置
  7. mysql5.7空间运算,深度解析MySQL5.7之临时表空间
  8. codevs1700 施工方案第二季
  9. 工业上 计算机控制系统分为哪两大类,控制仪表及装置——考试复习题
  10. python:configparser模块
  11. 15.supervisor 安装
  12. CSS实现文字描边效果
  13. 网站速度优化的三套解决方案
  14. 对话镕铭微电子CEO朱照远:未来几年视频处理芯片将成为一个万亿级的市场
  15. R语言windows函数自动生成可视化图像画布框、使用plot函数可视化数据点图、使用type参数指定数据点为实线
  16. 2018千元内的UGP VR一体机开箱评测:ugp vr一体机怎么样真的好吗?
  17. php圆角的度数计算公式,角度数换算公式(三角函数计算换算角度)
  18. mysql bytes sent_MySQL服务器状态变量(mysqld)
  19. 雨巷 喜欢文学 喜欢雨中撑伞的姑娘
  20. 百度竞价排名曝光_百度爱采购的三大优势,及如何发优质商品。

热门文章

  1. 图文详解 DBMS 数据库管理系统三层架构体系(三级模式)《ClickHouse 实战:企业级大数据分析引擎》...
  2. html自动播放avi视频,使用HTML5 video标签的一系列问题
  3. C++中文件开头写的 using namespace std 有什么作用?
  4. Week15—字典树应用,字符串包含问题
  5. 计算机应用 胡丹,正高级
  6. VS2019编译python解释器源码及学习方法
  7. ThinkPHP 虚拟主机 跳转public主页设置
  8. 91 Three.js Texture纹理属性详解
  9. android 复制asset文件下文件到手机指定路径,手机根目录
  10. matlab摩托车刹车问题,摩托车刹车你用对了吗?老司机都不一定会用后刹