swagger报错java.lang.NumberFormatException: For input string: ““,解决方法

1、问题出现

        偶然发现有一天,运行swagger会报java.lang.NumberFormatException: For input string: ""错误,出错的原因呢是因为 空字符串""无法转成Number

2、分析

        查阅大量资料发现是swagger版本的问题,我使用的是io.springfox:springfox-swagger2:2.9.2的版本,而该版本依赖了swagger-models1.5.20版本(会导致报此错),深挖原因是1.5.20版本中的example只判断了是否为null,没有判断是否为空串;1.5.21版本对两者都进行了判断。

在这里插入图片描述

 

 3、解决办法

        可以排除springfox-swagger2中的swagger-models依赖,导入io.swagger:swagger-models1.5.21版本即可。

        在pom.xml中将swagger修改为如下:

 <!--springboot 集成 swagger-->
        <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.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </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>


版权声明:本文为Vicky_2020原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。