swagger(版本2.9.2) 刷新报错,错误信息如下图:

问题原因:

根据上面这句报错信息,点进去AbstractSerializableParameter.java:412可以看到 源码,

@JsonProperty("x-example")
    public Object getExample() {
        if (example == null) {
            return null;
        }
        try {
            if (BaseIntegerProperty.TYPE.equals(type)) {
                return Long.valueOf(example);
            } else if (DecimalProperty.TYPE.equals(type)) {
                return Double.valueOf(example);
            } else if (BooleanProperty.TYPE.equals(type)) {
                if ("true".equalsIgnoreCase(example) || "false".equalsIgnoreCase(defaultValue)) {
                    return Boolean.valueOf(example);
                }
            }
        } catch (NumberFormatException e) {
            LOGGER.warn(String.format("Illegal DefaultValue %s for parameter type %s", defaultValue, type), e);
        }
        return example;
    }

Illegal DefaultValue null for parameter type integer`和`NumberFormatException: For input string: ""

从上面这句可以看出,有个默认值是空字符串的变量转换成Integer类型时异常。

也就是说如果实体属性类型是Integer,就把 example 转为 Long 类型,而example默认为 " " ,导致转换错误。

解决方案:

方法1.实体类中,Integer类型的属性加 @ApiModelProperty 时,必须要给example参数赋值,且值必须为数字类型。不推荐

@ApiModelProperty(value = "年龄",example = "22")
private Integer age;

方法2.新增配置,如下,推荐

     # 默认的配置
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency> <dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2。9.2</version>
</dependency>
# 增加两个配置
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.22</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
<version>1.5.22</version>
</dependency> 然后重启启动项目访问,问题解决。

swagger 报错:illegal defaultValue null for param type integer的更多相关文章

  1. springboot集成swagger2报Illegal DefaultValue null for parameter type integer

    springboot集成swagger2,实体类中有int类型,会报" Illegal DefaultValue null for parameter type integer"的 ...

  2. Swagger2异常:Illegal DefaultValue null for parameter type integer java

    一.异常分析: Illegal DefaultValue null for parameter type integer`和`NumberFormatException: For input stri ...

  3. swagger2 Illegal DefaultValue null for parameter type integer

    问题,为了方便调试,引入了swagger2,但是在第一次访问的时候总是报 Illegal DefaultValue null for parameter type integer 让人看着很不输入 定 ...

  4. 解决 Illegal DefaultValue null for parameter type integer 异常

    该异常是由 swagger 引起的 swagger 版本 1.9.2 解决原因:重新导入 swagger-annotations 和 swagger-models 版本 为 1.5.21 pom.xm ...

  5. swagger 报 i.s.m.parameters.AbstractSerializableParameter - Illegal DefaultValue null for parameter type integer java.lang.NumberFormatException: For input string

    解决 方法 添加这两个依赖....别问我有啥子用....我也不知道..能解决问题 <dependency> <groupId>io.swagger</groupId> ...

  6. 由ASP.NET Core WebApi添加Swagger报错引发的探究

    缘起 在使用ASP.NET Core进行WebApi项目开发的时候,相信很多人都会使用Swagger作为接口文档呈现工具.相信大家也用过或者了解过Swagger,这里咱们就不过多的介绍了.本篇文章记录 ...

  7. 【redis】5.spring boot项目中,直接在spring data jpa的Repository层使用redis +redis注解@Cacheable直接在Repository层使用,报错问题处理Null key returned for cache operation

    spring boot整合redis:http://www.cnblogs.com/sxdcgaq8080/p/8028970.html 首先,明确一下问题的场景 之前在spring boot整合re ...

  8. Chrome浏览器报错:Origin null is not allowed by Access-Control-Allow-Origin.

    问题:Chrome浏览器报错:Origin null is not allowed by Access-Control-Allow-Origin. 原因:.js文件中使用load()方法,而Chrom ...

  9. 同时操作两个数据库:报错Illegal attempt to associate a collection with two open sessions

    今天我在一个操作两个数据库的SSH里 同时插入1条数据 报错 Illegal attempt to associate a collection with two open sessions 在这里有 ...

随机推荐

  1. 02-线性结构3 Reversing Linked List (25 分)

    Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elem ...

  2. mysql帐号,权限管理

    -> use mysql; //选择数据库 -> select host,user,password from user; //查询已有用户 -> insert into user ...

  3. P1099 树网的核——模拟+树形结构

    P1099 树网的核 无根树,在直径上找到一条长度不超过s的路径,使得最远的点距离这条路径的距离最短: 首先两遍dfs找到直径(第二次找的时候一定要吧father[]清零) 在找到的直径下枚举长度不超 ...

  4. csp退役前的做题计划1(真)

    csp退役前的做题计划1(真) 因为我太菜了,所以在第一次月考就会退役,还是记录一下每天做了什么题目吧. 任务计划 [ ] Z算法(Z Algorithm) 9.28 [x] ARC061C たくさん ...

  5. 刷题记录:[0CTF 2016]piapiapia

    目录 刷题记录:[0CTF 2016]piapiapia 一.涉及知识点 1.数组绕过正则及相关 2.改变序列化字符串长度导致反序列化漏洞 二.解题方法 刷题记录:[0CTF 2016]piapiap ...

  6. 【大数据应用期末总评】Hadoop综合大作业

    作业要求来自:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE2/homework/3339 一.Hadoop综合大作业 要求: 1.将爬虫大作业产生的csv ...

  7. 如何在真实串口驱动还未加载的情况下调试uboot?

    1. 先找出真实串口是什么型号 1.1 怎么找?笔者提供两种方案: 方案一: 若当前的板子支持dm,从uboot的dts找串口节点对应的compatible属性 方案二: 从linux内核的dts找串 ...

  8. git - 3.分支

    分支介绍 每次提交,Git都把它们串成一条时间线,这条时间线就是一个分支.截止到目前,只有一条时间线, 在Git里,这个分支叫主分支,即master分支. HEAD严格来说不是指向提交,而是指向mas ...

  9. EF6中的SQL监控

    在MVC或WEBAPI中的监控 System.Action<string> action = (string message) => { Debug.WriteLine(messag ...

  10. ISO/IEC 9899:2011 条款1——范围

    1. 范围 1.本国际标准指定了C编程语言的形式并建立了对用C编程语言进行编写程序的诠释.[注:国际标准的设计是用于提升在多种数据处理系统中的C程序的可移植性.其目的在于能够被实现者与程序员所使用.] ...