Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean
Fixing Spring Boot error ‘Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.’
我最近基于 Gradle 依赖管理构建了一个新 SpringCloud +Spring WebFlux应用程序,从start.spring下载项目模板之后。io时,我添加了一些第三方依赖并尝试启动应用程序。然后我遇到了org.springframework.context 这个错误,ApplicationContextException:由于缺少ServletWebServerFactory bean,无法启动ServletWebServerApplicationContext
。实际上,当我搜索解决方案时,这是一个常见的问题。所有的解决方案都与Spring引导启动器缺少的依赖项有关。
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:156) ~[spring-boot-2.1.12.RELEASE.jar:2.1.12.RELEASE]at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-5.1.13.RELEASE.jar:5.1.13.RELEASE]at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.1.12.RELEASE.jar:2.1.12.RELEASE]at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744) ~[spring-boot-2.1.12.RELEASE.jar:2.1.12.RELEASE]at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391) ~[spring-boot-2.1.12.RELEASE.jar:2.1.12.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) ~[spring-boot-2.1.12.RELEASE.jar:2.1.12.RELEASE]at com.baimicro.central.GatewayApp.main(GatewayApp.java:27) [main/: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:203) ~[spring-boot-2.1.12.RELEASE.jar:2.1.12.RELEASE]at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:179) ~[spring-boot-2.1.12.RELEASE.jar:2.1.12.RELEASE]at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:153) ~[spring-boot-2.1.12.RELEASE.jar:2.1.12.RELEASE]... 6 common frames omitted
但这不是我项目的原因。我的项目是从 start.spring.io 创建的, 但在我添加了一些依赖项后,他就出现上述问题了。
错误消息是解决方案的线索,它说不能启动 ServletWebServerApplicationContext,但我的项目使用的是 WebFlux,它是一个反应性 web 项目,而不是一个基于servle t的Spring web MVC项目。
在 Spring 源代码中调试帮助我找到了原因。在 org.springframework.boot 的方法 deduceWebApplicationType 中,SpringApplication web 应用程序类型设置为WebApplicationType。仅当类路径中不存在Spring Web MVC的类时才响应,而在 Gradle 依赖项树 指出,新添加的一个库具有对 Spring -webmvc的过渡依赖,因此Spring -webmvc被添加到类路径中,Spring Boot 将该项目视为servlet应用程序。
private WebApplicationType deduceWebApplicationType() {if (ClassUtils.isPresent(REACTIVE_WEB_ENVIRONMENT_CLASS, null)&& !ClassUtils.isPresent(MVC_WEB_ENVIRONMENT_CLASS, null)) {return WebApplicationType.REACTIVE;}for (String className : WEB_ENVIRONMENT_CLASSES) {if (!ClassUtils.isPresent(className, null)) {return WebApplicationType.NONE;}}return WebApplicationType.SERVLET;}
一旦找到根本原因,解决方案就很容易,做法如下:
更新 Gradle 依赖项以排除spring-webmvc
或者将 web 应用程序类型设置为
WebApplicationType.REACTIVE
,具体如下所示public class GatewayApp {public static void main(String[] args) {SpringApplication application = new SpringApplication(GatewayApp.class);// 该设置方式 也可以解决我的前一个问题application.setWebApplicationType(WebApplicationType.REACTIVE);application.run(args);} }
Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean相关推荐
- Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean 解决方案
SpringBoot启动时的异常信息 "C:\Program Files\Java\jdk1.8.0_161\bin\java" ......... com.fangxing.ja ...
- 【Spring】Unable to start ServletWebServerApplicationContext due to miss ServletWebServerFactory bean
1.概述 我一个sparing boot项目,本地运行的时候报错. Unable to start ServletWebServerApplicationContext due to miss Ser ...
- 本地启动出错Unable to start ServletWebServerApplicationContext due to miss ServletWebServerFactory bean
Springboot项目打包成war上传到云服务器后,本地启动出错. 首先,我们去除为了上传云服务器所添加的步骤,详细见我的另一篇文章Springboot项目部署到阿里云服务器(war和jar) 然后 ...
- 【Spring] Spring boot 报错 Unable to start ServletWebServerApplicationContext due to missing ServletWe
1.概述 spring 报错如下 Error starting ApplicationContext. To display the conditions report re-run your app ...
- missing ServletWebServerFactory bean
点击了报错行,在报错行打了个断点,发现是没取到这个bean. 启动了另一个web项目,同样一个地方打了断点,发现取到的是tomcatServletWebServerFactory. 判断到没有引入to ...
- Spring Boot: Unable to start EmbeddedWebApplicationContext due to missing Embedd
spring boot启动时报错: Spring Boot: Unable to start EmbeddedWebApplicationContext due to missing Embedded ...
- 如何处理错误消息Unable to install breakpoint due to missing line number attributes
Created by Wang, Jerry, last modified on Mar 11, 2017 Unable to install breakpoint due to missing li ...
- “Unable to install breakpoint due to missing line number attributes,Modify compiler options togenera
Unable to install breakpoint in处理方法 (2012-12-27 10:16:44) 转载▼ 标签: 杂谈 分类: 有java的哈皮时光 今天调试程序的时候,eclips ...
- Unable to install breakpoint in XXX due to missing line number attributes的解决
Eclipse下Debug时弹出错误"Unable to install breakpoint due to missing line number attributes,Modify co ...
- 创建vue项目的时候报错:Skipped git commit due to missing username and email in git config.
创建vue项目的时候报错: WARN Skipped git commit due to missing username and email in git config, or failed to ...
最新文章
- Ado.Net 连接数据库
- 代码控制UI,View
- 完全虚拟化和半虚拟化区别
- 整理iOS9适配中出现的坑
- 现代软件工程 第十四章 【质量保障】 练习与讨论
- Spring详细导包截图以及IOC和DI思想
- ABP理论之CSRF
- 【搜狗拼音输入法 3.2 论坛版】
- 3D打印Gcode文件命令详解
- AppFuse 安装
- Oplayer HDiPad最实用的视频播放器
- 哪款蓝牙耳机性价比最高?无线蓝牙耳机性价比排行榜
- ucore lab2
- GAPIT 3.0:全基因组关联分析与预测软件最新版发布
- 超参数优化:网格搜索法
- python爬取网页教程(一个小案例分享)
- XML DTD Schema 学习-Schema 介绍
- C 语言程序的执行流程
- springboot毕设项目网上图书商城q3ulr(java+VUE+Mybatis+Maven+Mysql)
- 数据库学习笔记六、数据库并发策略