zoukankan      html  css  js  c++  java
  • Swagger2异常 java.lang.NumberFormatException: For input string: ""

    问题
    在访问swagger首页时报错:

    java.lang.NumberFormatException: For input string: ""
        at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
        at java.lang.Long.parseLong(Long.java:601)
        at java.lang.Long.valueOf(Long.java:803)
        at io.swagger.models.parameters.AbstractSerializableParameter.getExample(AbstractSerializableParameter.java:412)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:687)
        at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:719)

    报错的版本是2.9.2,2.7.0的版本是不报错的,2.8的版本也不会
    我的依赖是这样的

           <dependency>
             <groupId>io.springfox</groupId>
             <artifactId>springfox-swagger2</artifactId>
    <!--         <version>2.7.0</version>-->
             <version>2.9.2</version>
          </dependency>
          <dependency>
             <groupId>io.springfox</groupId>
             <artifactId>springfox-swagger-ui</artifactId>
    <!--         <version>2.7.0</version>-->
             <version>2.9.2</version>
          </dependency>

    原因
    AbstractSerializableParameter.class 

    默认值为"",如果没有@ApiModelProperty(value = "id",example = "123")设置example值,则会出现上面异常

    解决
    修改swagger-models版本,1.5.21进行了修复

    pom.xml文件修改为

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

    或者是选择降低版本,使用2.7或者2.8

  • 相关阅读:
    声明了变量并赋了初始值,但在VS中报当前上下文中不存在名称“ XXX”的错误 Kevin
    delphi中的nil值 Kevin
    MVC3 + Ajax 图片上传总结 Kevin
    EntityFramework 更新数据库的问题 Kevin
    MVC3 EntityFramework 插入Mysql数据库 乱码问题 Kevin
    MVC Html 编码问题 Kevin
    周鸿祎:共享软件无合理商业模式才变流氓
    C++界面库 Xtreme Toolkit Pro[转载]
    《创业10个小诀窍》
    软件商业模式分析之-迅雷
  • 原文地址:https://www.cnblogs.com/weianlai/p/11352143.html
Copyright © 2011-2022 走看看