> 技术文档 > SpringBoot3整合Swagger3时出现Type javax.servlet.http.HttpServletRequest not present错误_springboot3.4 整合swagger时 : typenotpresentexception

SpringBoot3整合Swagger3时出现Type javax.servlet.http.HttpServletRequest not present错误_springboot3.4 整合swagger时 : typenotpresentexception

目录

错误详情

错误原因

解决方法

引入依赖

修改配置信息 

创建文件 

访问 


错误详情

错误原因

SpringBoot3和Swagger3版本不匹配

解决方法

使用springdoc替代springfox,具体步骤如下:

引入依赖

在pom.xml文件中添加如下依赖:

 org.springdoc springdoc-openapi-starter-webmvc-ui 2.0.2 org.springdoc springdoc-openapi-starter-webmvc-api 2.0.2
修改配置信息 

在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;@Configurationpublic 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

如果显示如下界面,就成功了!!!