spring boot3.x集成swagger出现Type javax.servlet.http.HttpServletRequest not present

1. 问题出现原因

spring boot3.x版本依赖于jakarta依赖包,但是swagger依赖底层应用的javax依赖包,所以只要已启动就会报错。

2. 解决方案

移除swagger2依赖

xml 复制代码
<dependency>
     <groupId>io.springfox</groupId>
     <artifactId>springfox-swagger2</artifactId>
     <version>2.9.2</version>
 </dependency>

 <dependency>
     <groupId>com.github.xiaoymin</groupId>
     <artifactId>swagger-bootstrap-ui</artifactId>
     <version>1.9.0</version>
     <scope>provided</scope>
 </dependency>

添加新依赖

xml 复制代码
<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
    <version>2.1.0</version>
</dependency>

标签替换

@Api(tags = "") → @Tag(name = "")

@ApiModel(value="", description="") → @Schema(name="", description="")

@ApiModelProperty(value = "", required = true) → @Schema(name= "", description = "", required = true)

@ApiOperation(value = "", notes = "") → @Operation(summary = "", description = "")

@ApiParam → @Parameter

@ApiResponse(code = 404, message = "") → @ApiResponse(responseCode = "404", description = "")

相关推荐
coderWangbuer20 分钟前
基于springboot的高校招生系统(含源码+sql+视频导入教程+文档+PPT)
spring boot·后端·sql
Kenny.志28 分钟前
2、Spring Boot 3.x 集成 Feign
java·spring boot·后端
sky丶Mamba1 小时前
Spring Boot中获取application.yml中属性的几种方式
java·spring boot·后端
读心悦2 小时前
如何在 Axios 中封装事件中心EventEmitter
javascript·http
千里码aicood2 小时前
【2025】springboot教学评价管理系统(源码+文档+调试+答疑)
java·spring boot·后端·教学管理系统
程序员-珍2 小时前
使用openapi生成前端请求文件报错 ‘Token “Integer“ does not exist.‘
java·前端·spring boot·后端·restful·个人开发
CXDNW2 小时前
【网络篇】计算机网络——应用层详述(笔记)
服务器·笔记·计算机网络·http·web·cdn·dns
liuxin334455663 小时前
教育技术革新:SpringBoot在线教育系统开发
数据库·spring boot·后端
秋夫人4 小时前
http cache-control
网络·网络协议·http
叶北辰CHINA4 小时前
nginx反向代理,负载均衡,HTTP配置简述(说人话)
linux·运维·nginx·http·云原生·https·负载均衡