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

 更新时间:2020年12月25日 11:31:07   作者:gopyja  
这篇文章主要介绍了springboot使用swagger-ui 2.10.5 有关版本更新带来的问题小结,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

问题1

常见问题

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

 <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>

将原来默认的 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 文件应该引入如下配置:

<dependency>
			<groupId>io.springfox</groupId>
			<artifactId>springfox-spring-webflux</artifactId>
			<version>2.10.5</version>
		</dependency>

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

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

<dependency>
			<groupId>io.springfox</groupId>
			<artifactId>springfox-spring-webmvc</artifactId>
			<version>2.10.5</version>
		</dependency>

同时可以在 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;
/**
 * @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("后台登录")
        .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版本问题内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • 详谈fastjson将对象格式化成json时的两个问题

    详谈fastjson将对象格式化成json时的两个问题

    下面小编就为大家带来一篇详谈fastjson将对象格式化成json时的两个问题。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-05-05
  • java实现简单五子棋小游戏(1)

    java实现简单五子棋小游戏(1)

    这篇文章主要为大家详细介绍了java实现简单五子棋小游戏的第一部分,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-01-01
  • Java关于BeabUtils.copyproperties的用法

    Java关于BeabUtils.copyproperties的用法

    这篇文章主要介绍了Java关于BeabUtils.copyproperties的用法,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2024-08-08
  • Java虚拟机栈jvm栈的作用

    Java虚拟机栈jvm栈的作用

    本文主要介绍了Java虚拟机栈jvm栈的作用,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2021-11-11
  • Java中的clone()和Cloneable接口实例

    Java中的clone()和Cloneable接口实例

    这篇文章主要介绍了Java中的clone()和Cloneable接口实例,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2021-11-11
  • Java多线程之ThreadLocal原理总结

    Java多线程之ThreadLocal原理总结

    这篇文章主要介绍了Java多线程ThreadLocal原理,同一个ThreadLocal所包含的对象,在不同的Thread中有不同的副本,文章中有详细的代码示例,需要的朋友参考一下
    2023-04-04
  • 带你快速搞定java多线程

    带你快速搞定java多线程

    这篇文章主要介绍了java多线程编程实例,分享了几则多线程的实例代码,具有一定参考价值,加深多线程编程的理解还是很有帮助的,需要的朋友可以参考下
    2021-07-07
  • Mybatis两种不同批量插入方式的区别

    Mybatis两种不同批量插入方式的区别

    随着业务需要,有时我们需要将数据批量添加到数据库,mybatis提供了将list集合循环添加到数据库的方法,这篇文章主要给大家介绍了关于Mybatis两种不同批量插入方式的区别,需要的朋友可以参考下
    2021-09-09
  • Spring 中优雅的获取泛型信息的方法

    Spring 中优雅的获取泛型信息的方法

    这篇文章主要介绍了Spring 中优雅的获取泛型信息的方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-03-03
  • 浅谈一下maven优缺点及使用和特点

    浅谈一下maven优缺点及使用和特点

    这篇文章主要介绍了浅谈一下maven优缺点及使用和特点,一个项目管理工具软件,那么maven项目有什么优缺点呢,让我们一起来看看吧
    2023-03-03

最新评论