SpringBoot3整合Swagger3时出现Type javax.servlet.http.H的ttpServletRequest not present错误解决方法
错误详情


错误原因
SpringBoot3和Swagger3版本不匹配
解决方法
使用springdoc替代springfox,具体步骤如下:
引入依赖
在pom.xml文件中添加如下依赖:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
<version>2.0.2</version>
</dependency>修改配置信息
在application.yml中添加如下内容:
springdoc: swagger-ui.path: /swagger-ui.html
创建文件
创建一个SwaggerConfig.java文件,并添加一下内容:
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class SwaggerConfig {
@Bean
public OpenAPI springShopOpenAPI() {
return new OpenAPI()
.info(new Info().title("SpringBoot Vue Test")
.description("SpringBoot+Vue Test Swagger debugging")
.version("v1"));
}
}访问
启动项目访问 127.0.0.1:20000/swagger-ui/index.html
如果显示如下界面,就成功了!!!

到此这篇关于SpringBoot3整合Swagger3时出现Type javax.servlet.http.H的ttpServletRequest not present错误解决方法的文章就介绍到这了,更多相关SpringBoot3整合Swagger3报错内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
spring boot只需两步优雅整合activiti示例解析
这篇文章主要主要来教大家spring boot优雅整合activiti只需两步就可完成测操作示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助祝大家多多进步2022-03-03
解决SpringCloud Config结合github无法读取配置的问题
这篇文章主要介绍了解决SpringCloud Config结合github无法读取配置的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧2021-02-02


最新评论