springboot使用swagger-ui 2.10.5 有關(guān)版本更新帶來的問題小結(jié)
問題1
常見問題
1.需要傳入后臺(tái)的為string類型 但是使用swagger-ui 接口進(jìn)行測(cè)試的時(shí)候,輸入的為數(shù)字類型,建議對(duì)pom.xml文件進(jìn)行調(diào)整
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>${swagger.version}</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>${swagger.version}</version> <exclusions> <exclusion> <groupId>io.swagger</groupId> <artifactId>swagger-annotations</artifactId> </exclusion> <exclusion> <groupId>io.swagger</groupId> <artifactId>swagger-models</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>io.swagger</groupId> <artifactId>swagger-annotations</artifactId> <version>1.5.21</version> </dependency> <dependency> <groupId>io.swagger</groupId> <artifactId>swagger-models</artifactId> <version>1.5.21</version> </dependency>
將原來默認(rèn)的 1.5.20 版本剔除,此時(shí)的 swagger.version 默認(rèn)為 2.10.5,默認(rèn)引入的為1.5.20,可以剔除再引入新的1.5.21.
2.出現(xiàn)如下的圖片的問題
Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API
Gateway. The base url is the root of where all the swagger resources are served. For e.g. if the api is available at
http://example.org/api/v2/api-docs then the base url is http://example.org/api/. Please enter the location manually:
圖片入下圖所示:
Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API
Gateway. The base url is the root of where all the swagger resources are served. For e.g. if the api is available at
http://example.org/api/v2/api-docs then the base url is http://example.org/api/. Please enter the location manually:
此時(shí)查看 pom.xml 的文件是否滿足要求, 這里的 /api/dataStandard 路徑為后臺(tái) yml 或者 properties 文件中的路徑,例如:
server: port: 18088 servlet: context-path: /api/dataStandard
因swagger-ui Java使用的是 2.10.5 版本,此版本與 3.0 和 原有2.9 版本及以下的版本不同,如果你選擇使用 webflux 進(jìn)行開發(fā)此時(shí)的pom.xml 文件應(yīng)該引入如下配置:
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-spring-webflux</artifactId> <version>2.10.5</version> </dependency>
同時(shí)可以在 SwaggerConfig.java 文件加上 @EnableSwagger2WebFlux 此配置,不然使用原有的 @EnableSwagger2 或者使用成 @EnableSwagger2WebMvc 會(huì)出現(xiàn)圖片出現(xiàn)的錯(cuò)誤。
如果你使用的是 springboot-web 進(jìn)行開發(fā),此時(shí)應(yīng)該引入 pom.xml 如下配置:
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-spring-webmvc</artifactId> <version>2.10.5</version> </dependency>
同時(shí)可以在 SwaggerConfig.java 文件加上 @EnableSwagger2WebMvc 此配置,不然使用原有的 @EnableSwagger2 或者使用成 @EnableSwagger2WebFlux 會(huì)出現(xiàn)圖片出現(xiàn)的錯(cuò)誤。
具體 SwaggerConfig.java 如題下所示:
import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.service.ApiInfo; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc; /** * @author hzp * @date 2020.11.05 */ @EnableSwagger2WebMvc @Configuration public class SwaggerConfig { @Value("${swagger.enabled}") private Boolean enabled; @Bean @SuppressWarnings("all") public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .enable(enabled) .apiInfo(apiInfo()) .pathMapping("/") .select() .apis(RequestHandlerSelectors.basePackage("com.hzp.app.web")) .paths(PathSelectors.any()) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("sso-server 接口文檔") .description("后臺(tái)登錄") .version("1.0") .build(); } }
${swagger.enabled}
取yml中設(shè)置的是否啟用 swagger-ui
功能,如下xml:
#是否開啟 swagger-ui swagger: enabled: true
以上為 springboot 采用 2.10.5 版本開發(fā)時(shí)遇到的一點(diǎn)問題,希望不足的地方大家給予意見。
到此這篇關(guān)于springboot使用swagger-ui 2.10.5 有關(guān)版本更新帶來的問題小結(jié)的文章就介紹到這了,更多相關(guān)springboot使用swagger-ui 2版本問題內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
SpringBoot中的靜態(tài)資源訪問的實(shí)現(xiàn)
這篇文章主要介紹了SpringBoot中的靜態(tài)資源訪問的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-09-09關(guān)于Kafka消息隊(duì)列原理的總結(jié)
這篇文章主要介紹了關(guān)于Kafka消息隊(duì)列原理的總結(jié),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-05-05java動(dòng)態(tài)代理和cglib動(dòng)態(tài)代理示例分享
這篇文章主要介紹了java動(dòng)態(tài)代理和cglib動(dòng)態(tài)代理示例,JDK1.3之后,Java提供了動(dòng)態(tài)代理的技術(shù),允許開發(fā)者在運(yùn)行期間創(chuàng)建接口的代理實(shí)例,下面我們使用示例學(xué)習(xí)一下2014-03-03使用Spring Cache和Redis實(shí)現(xiàn)查詢數(shù)據(jù)緩存
在現(xiàn)代應(yīng)用程序中,查詢緩存的使用已經(jīng)變得越來越普遍,它不僅能夠顯著提高系統(tǒng)的性能,還能提升用戶體驗(yàn),在這篇文章中,我們將探討緩存的基本概念、重要性以及如何使用Spring Cache和Redis實(shí)現(xiàn)查詢數(shù)據(jù)緩存,需要的朋友可以參考下2024-07-07JAVA實(shí)現(xiàn)用戶抽獎(jiǎng)功能(附完整代碼)
這篇文章主要給大家介紹了關(guān)于JAVA實(shí)現(xiàn)用戶抽獎(jiǎng)功能的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11