SpringBoot项目集成swagger报NumberFormatException: For input string: ""

java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[?:1.8.0_242]

出现此错误,就是应该导入了多个版本的swagger依赖

<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>

<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>

通过IDEA提供的依赖图查看,项目中存在 1.5.20版本和2.1.2版本,需要排除1.5.20版本的依赖;解决方法如下:替换swagger的依赖包即可
<dependency>
      <groupId>io.springfox</groupId>
      <artifactId>springfox-boot-starter</artifactId>
      <version>3.0.0</version>
      <exclusions>
        <exclusion>
          <artifactId>swagger-models</artifactId>
          <groupId>io.swagger</groupId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>io.springfox</groupId>
      <artifactId>springfox-swagger-common</artifactId>
      <version>3.0.0</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-swagger2</artifactId>
      <version>3.0.0</version>
      <scope>compile</scope>
      <exclusions>
        <exclusion>
          <groupId>io.swagger</groupId>
          <artifactId>swagger-annotations</artifactId>
        </exclusion>
        <exclusion>
          <groupId>io.swagger</groupId>
          <artifactId>swagger-models</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

因为

springfox-boot-starter:3.0 依赖导入了2个版本,所以只需要把低版本排除即可



其他问题:如果把1.5.20低版本给去掉的话,会报io.swagger.models依赖找不到
所以添加最新版1.6.2版本即可
    <dependency>
      <groupId>io.swagger</groupId>
      <artifactId>swagger-models</artifactId>
      <version>1.6.2</version>
    </dependency>
    <dependency>
      <groupId>io.swagger</groupId>
      <artifactId>swagger-annotations</artifactId>
      <version>1.6.2</version>
    </dependency>

swagger快捷导航:

 1. Swagger-code 1.5.X注解

 2. Swagger-code 2.0注解(基本不可用):大部分注解的属性使用没有效果 ,如@Schema里的description属性没有通过swagger api接口返回,页面并未展示,还有其他坑

3. Swagger-Code 入门导航




Swagger2.0的注解不清楚为什么不起作用,有知道的朋友请在下方评论交流,网络上基本都是介绍Swagger1.5.X的注解
复制请注明出处,在世界中挣扎的灰太狼
原文地址:https://www.cnblogs.com/XingXiaoMeng/p/13800508.html