栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

springboot使用swagger-ui 2.10.5 有关版本更新带来的问题小结

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

springboot使用swagger-ui 2.10.5 有关版本更新带来的问题小结

问题1

常见问题

1.需要传入后台的为string类型 但是使用swagger-ui 接口进行测试的时候,输入的为数字类型,建议对pom.xml文件进行调整

 
			io.springfox
			springfox-swagger2
			${swagger.version}
		
		
			io.springfox
			springfox-swagger-ui
			${swagger.version}
			
				
					io.swagger
					swagger-annotations
				
				
					io.swagger
					swagger-models
				
			
		
		
			io.swagger
			swagger-annotations
			1.5.21
		
		
			io.swagger
			swagger-models
			1.5.21
		

将原来默认的 1.5.20 版本剔除,此时的 swagger.version 默认为 2.10.5,默认引入的为1.5.20,可以剔除再引入新的1.5.21.

2.出现如下的图片的问题

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:

此时查看 pom.xml 的文件是否满足要求, 这里的 /api/dataStandard 路径为后台 yml 或者 properties 文件中的路径,例如:

server:
 port: 18088
 servlet:
  context-path: /api/dataStandard

因swagger-ui Java使用的是 2.10.5 版本,此版本与 3.0 和 原有2.9 版本及以下的版本不同,如果你选择使用 webflux 进行开发此时的pom.xml 文件应该引入如下配置:


			io.springfox
			springfox-spring-webflux
			2.10.5
		

同时可以在 SwaggerConfig.java 文件加上 @EnableSwagger2WebFlux 此配置,不然使用原有的 @EnableSwagger2 或者使用成 @EnableSwagger2WebMvc 会出现图片出现的错误。

如果你使用的是 springboot-web 进行开发,此时应该引入 pom.xml 如下配置:


			io.springfox
			springfox-spring-webmvc
			2.10.5
		

同时可以在 SwaggerConfig.java 文件加上 @EnableSwagger2WebMvc 此配置,不然使用原有的 @EnableSwagger2 或者使用成 @EnableSwagger2WebFlux 会出现图片出现的错误。

具体 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;

@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("后台登录")
 .version("1.0")
 .build();
  }

}

${swagger.enabled} 取yml中设置的是否启用 swagger-ui 功能,如下xml:

#是否开启 swagger-ui
swagger:
 enabled: true

以上为 springboot 采用 2.10.5 版本开发时遇到的一点问题,希望不足的地方大家给予意见。

到此这篇关于springboot使用swagger-ui 2.10.5 有关版本更新带来的问题小结的文章就介绍到这了,更多相关springboot使用swagger-ui 2版本问题内容请搜索考高分网以前的文章或继续浏览下面的相关文章希望大家以后多多支持考高分网!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/129693.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号