当前位置:   article > 正文

Swagger报错,访问测试接口页面doc.html报错:java.lang.NumberFormatException: For input string: ““,swagger-ui插件的使用_swagger3 doc.html 错误

swagger3 doc.html 错误

之前我们测试接口,都是使用 postman 工具,而 Swagger2 给出了测试接口的文档,使用方式如下:

1、添加依赖:

<dependency>
    <groupId>com.github.xiaoymin</groupId>
    <artifactId>swagger-bootstrap-ui</artifactId>
    <version>1.9.6</version>
</dependency>
  • 1
  • 2
  • 3
  • 4
  • 5

2、浏览器访问:localhost:项目启动的端口/doc.html

报错: 可以正常访问,但是 IDEA 报错:java.lang.NumberFormatException: For input string: ""

分析: 该 Swagger 版本下对于数字类型的字段没有设置 example 值,导致 Swagger 处理时类型转换异常,算是swagger-models 1.5.20 的一个小 bug:

解决: 排除 springfox-swagger2 中的 swagger-models 依赖,导入 swagger-models1.5.21版本(或者1.5.22)即可:

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.9.2</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
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/83569
推荐阅读
相关标签
  

闽ICP备14008679号