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. 【洛谷P3369】普通平衡树——Splay学习笔记(一)

    二叉搜索树(二叉排序树) 概念:一棵树,若它的左子树不空,则左子树上所有结点的值均小于它的根结点的值: 若它的右子树不空,则右子树上所有结点的值均大于它的根结点的值: 它的左.右子树也分别为二叉搜索树 ...

  2. 转载:SVD

    ComputeSVD        在分布式矩阵有CoordinateMatirx, RowMatrix, IndexedRowMatrix三种.除了CoordinateMatrix之外,Indexe ...

  3. GoCN每日新闻(2019-10-24)

    GoCN每日新闻(2019-10-24) GoCN每日新闻(2019-10-24) 1. 学习Golang之服务器框架编写 – CS网络通信 http://1t.click/aJag 2. 如何实现 ...

  4. [Beta]第四次 Scrum Meeting

    [Beta]第四次 Scrum Meeting 写在前面 会议时间 会议时长 会议地点 2019/5/12 22:00 30min 大运村公寓6F楼道 附Github仓库:WEDO 例会照片 工作情况 ...

  5. bean名称相同冲突Annotation-specified bean name 'xx' for bean class [xxx] conflicts with existing, non-compatible bean definition of same name and class[xxx]

    工程中引入其他工程的包,由于两个工程中有重名的两个bean,导致在启动时提示如下错误: 根据bean名称在ide中查找,找到这两个重名的类,可以看到由于这两个类使用@Service标注,此时如果不使用 ...

  6. 运维笔记--linux下忘记mysql root密码

    补充链接:Windows下忘记密码处理: https://www.cnblogs.com/hellojesson/p/5972950.html 场景描述: Linux环境下忘记 root 密码, 1. ...

  7. debug console不见了

    点击左侧这个标志.

  8. 一起学习epoll

    epoll 是Linux内核中的一种可扩展IO事件处理机制,最早在 Linux 2.5.44内核中引入,可被用于代替POSIX select 和 poll 系统调用,并且在具有大量应用程序请求时能够获 ...

  9. [LeetCode] 387. First Unique Character in a String 字符串的第一个唯一字符

    Given a string, find the first non-repeating character in it and return it's index. If it doesn't ex ...

  10. [LeetCode] 602. Friend Requests II: Who Has Most Friend? 朋友请求 II: 谁有最多的朋友?

    In social network like Facebook or Twitter, people send friend requests and accept others' requests ...