• swagger2 Illegal DefaultValue null for parameter type integer


    问题,为了方便调试,引入了swagger2,但是在第一次访问的时候总是报

    Illegal DefaultValue null for parameter type integer 让人看着很不输入

    定位问题

    很明显说是NumberFormatException,查看AbstractSerializableParameter的getExample得知

        @JsonProperty("x-example")
        public Object getExample() {
            if (this.example == null) {
                return null;
            } else {
                try {
                    if ("integer".equals(this.type)) {
                        return Long.valueOf(this.example);
                    }
    

    在进行转化的时候报错,在this.example == null判断的不对。

    解决

    方式1-修改源码

    将源码下载下来,进行编辑,把判断部分修改为if (example == null || example.isEmpty())
    之后将其打包上传到maven私服即可。
    弊端,修改源码只能上传到私服,麻烦,也比较难

    方式2-修改代码

        @ApiModelProperty("开始时间,时间戳")
        private Long timeBegin;
    

    修改为

        @ApiModelProperty(value = "开始时间,时间戳",example = "0")
        private Long timeBegin;
    

    很明显,最容易,但是改动的也不少。

    方式3-修改依赖

    看网上说在swagger-models 1.5.21版本修复了该问题

    所以要升级版本

    exclusions排除依赖


    通过maven integration extension插件将swagger-models 1.5.20依赖排除
    再引入1.5.21依赖,如下代码

        <dependency>
          <groupId>io.springfox</groupId>
          <artifactId>springfox-swagger2</artifactId>
          <version>2.9.2</version>
          <exclusions>
            <exclusion>
              <artifactId>swagger-models</artifactId>
              <groupId>io.swagger</groupId>
            </exclusion>
          </exclusions>
        </dependency>
    

    再查看源码

    ok,完美解决!

  • 相关阅读:
    移动端开发rem布局之less+媒体查询布局的原理步骤和心得
    前端实现文件下载方式总汇
    如何能提高CSS编写技巧?提高Web前端开发效率
    常用的CSS命名规则
    CSS背景background
    CSS盒子模型
    简单的树形菜单如何写?
    彻底掌握css动画【transition】
    首页白屏优化实践
    我来聊聊面向模板的前端开发
  • 原文地址:https://www.cnblogs.com/exmyth/p/15596980.html
Copyright © 2020-2023  润新知