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
創(chuàng)建文件
創(chuàng)建一個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
如果顯示如下界面,就成功了?。。?/p>
到此這篇關于SpringBoot3整合Swagger3時出現Type javax.servlet.http.H的ttpServletRequest not present錯誤解決方法的文章就介紹到這了,更多相關SpringBoot3整合Swagger3報錯內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
spring profile 多環(huán)境配置管理詳解
這篇文章主要介紹了 spring profile 多環(huán)境配置管理詳解的相關資料,需要的朋友可以參考下2017-01-01spring?boot只需兩步優(yōu)雅整合activiti示例解析
這篇文章主要主要來教大家spring?boot優(yōu)雅整合activiti只需兩步就可完成測操作示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助祝大家多多進步2022-03-03解決SpringCloud Config結合github無法讀取配置的問題
這篇文章主要介紹了解決SpringCloud Config結合github無法讀取配置的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-02-02