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 = "")

相关推荐
灰子学技术1 天前
Envoy HTTP Connection Manager (HCM) 技术文档
网络·网络协议·http
默 语1 天前
基于 Spring Boot 3 + LangChain4j 快速构建企业级 AI 应用实战
人工智能·spring boot·后端
薪火铺子1 天前
SpringBoot WebServer启动与监听器原理深度解析
spring boot·后端·tomcat
KmSH8umpK1 天前
SpringBoot 分布式锁实战:从单机锁到Redis分布式锁全覆盖,解决超卖、重复下单、幂等并发问题
spring boot·redis·分布式
jay神1 天前
基于团队模式的C程序设计课程辅助教学管理系统
java·spring boot·vue·web开发·管理系统
长河1 天前
基于 Jib 实现无 Dockerfile 的 Spring Boot 应用容器化
java·spring boot·后端
Arya_aa1 天前
一:病虫害 AI 识别系统项目初期准备与Docker初识,VM虚拟机
spring boot
敖正炀1 天前
Spring MVC 启动全景:DispatcherServlet 与父子容器
spring boot
七七powerful1 天前
AI+运维提效--HTTPS 证书有效期监控方案
网络协议·http·https