Spring Boot启动报错tomcatReactiveWebServerFactory,缺失jakarta/servlet/Servlet需补何依赖?
问题分析与解决
首先,你存在两个关键问题:
- 错误引入
spring-boot-starter-parent:它不是普通依赖,是Spring Boot用来统一版本、管理插件的父项目,不能用implementation添加到依赖列表里。 - 依赖冗余+缺失必要组件:重复引入的
spring-boot-starter完全多余,而当项目触发Tomcat作为反应式服务器逻辑时,缺少Servlet API相关依赖。
正确的build.gradle配置
plugins { id 'org.springframework.boot' version '3.0.2' id 'java' } parent { group 'org.springframework.boot' name 'spring-boot-starter-parent' version '3.0.2' } dependencies { // WebFlux Starter已包含基础Spring Boot核心依赖,无需单独引入spring-boot-starter implementation 'org.springframework.boot:spring-boot-starter-webflux' // 若你明确需要用Tomcat作为反应式服务器,添加此依赖(默认用Netty,可省略) implementation 'org.springframework.boot:spring-boot-starter-tomcat' }
报错原因说明
WebFlux默认使用Netty作为内置服务器,不会涉及Servlet API。但你的配置混乱(错误将parent作为依赖引入),导致项目尝试启用Tomcat作为反应式服务器,此时缺少Servlet API相关依赖,就会抛出jakarta/servlet/Servlet找不到的异常。
内容的提问来源于stack exchange,提问作者SillyQuestion
相关产品推荐
相关产品推荐

