SpringBoot3整合Swagger3時(shí)出現(xiàn)Type javax.servlet.http.H的ttpServletRequest not present錯(cuò)誤解決方法
錯(cuò)誤詳情
錯(cuò)誤原因
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中添加如下內(nèi)容:
springdoc: swagger-ui.path: /swagger-ui.html
創(chuàng)建文件
創(chuàng)建一個(gè)SwaggerConfig.java文件,并添加一下內(nèi)容:
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")); } }
訪問
啟動(dòng)項(xiàng)目訪問 127.0.0.1:20000/swagger-ui/index.html
如果顯示如下界面,就成功了?。?!
到此這篇關(guān)于SpringBoot3整合Swagger3時(shí)出現(xiàn)Type javax.servlet.http.H的ttpServletRequest not present錯(cuò)誤解決方法的文章就介紹到這了,更多相關(guān)SpringBoot3整合Swagger3報(bào)錯(cuò)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Java?zxing實(shí)現(xiàn)生成并解析二維碼與條形碼
這篇文章主要為大家詳細(xì)介紹了Java如何通過zxing實(shí)現(xiàn)生成并解析二維碼與條形碼,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解下2024-11-11spring profile 多環(huán)境配置管理詳解
這篇文章主要介紹了 spring profile 多環(huán)境配置管理詳解的相關(guān)資料,需要的朋友可以參考下2017-01-01spring?boot只需兩步優(yōu)雅整合activiti示例解析
這篇文章主要主要來教大家spring?boot優(yōu)雅整合activiti只需兩步就可完成測(cè)操作示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助祝大家多多進(jìn)步2022-03-03解決SpringCloud Config結(jié)合github無法讀取配置的問題
這篇文章主要介紹了解決SpringCloud Config結(jié)合github無法讀取配置的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2021-02-02