swagger 报错:illegal defaultValue null for param type integer
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的更多相关文章
- springboot集成swagger2报Illegal DefaultValue null for parameter type integer
springboot集成swagger2,实体类中有int类型,会报" Illegal DefaultValue null for parameter type integer"的 ...
- Swagger2异常:Illegal DefaultValue null for parameter type integer java
一.异常分析: Illegal DefaultValue null for parameter type integer`和`NumberFormatException: For input stri ...
- swagger2 Illegal DefaultValue null for parameter type integer
问题,为了方便调试,引入了swagger2,但是在第一次访问的时候总是报 Illegal DefaultValue null for parameter type integer 让人看着很不输入 定 ...
- 解决 Illegal DefaultValue null for parameter type integer 异常
该异常是由 swagger 引起的 swagger 版本 1.9.2 解决原因:重新导入 swagger-annotations 和 swagger-models 版本 为 1.5.21 pom.xm ...
- swagger 报 i.s.m.parameters.AbstractSerializableParameter - Illegal DefaultValue null for parameter type integer java.lang.NumberFormatException: For input string
解决 方法 添加这两个依赖....别问我有啥子用....我也不知道..能解决问题 <dependency> <groupId>io.swagger</groupId> ...
- 由ASP.NET Core WebApi添加Swagger报错引发的探究
缘起 在使用ASP.NET Core进行WebApi项目开发的时候,相信很多人都会使用Swagger作为接口文档呈现工具.相信大家也用过或者了解过Swagger,这里咱们就不过多的介绍了.本篇文章记录 ...
- 【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 ...
- 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 ...
- 同时操作两个数据库:报错Illegal attempt to associate a collection with two open sessions
今天我在一个操作两个数据库的SSH里 同时插入1条数据 报错 Illegal attempt to associate a collection with two open sessions 在这里有 ...
随机推荐
- JAVA中Stringbuffer的append( )方法
Stringbuffer是动态字符串数组,append( )是往动态字符串数组添加,跟“xxxx”+“yyyy”相当‘+’号. 跟String不同的是Stringbuffer是放一起的,String1 ...
- ICEM-哑铃(无厚度)
原视频下载地址:https://pan.baidu.com/s/1i44hdkh 密码: 96dh
- pxe问题
可能镜像路径问题 https://blog.csdn.net/geek_tank/article/details/69479196 一.vmlinuz vmlinuz是可引导的.压缩的内核.“vm”代 ...
- 为什么用ls和du显示出来的文件大小有差别?【转】
在使用Linux ls命令查看文件大小时,发现文件很大,足有100个G,而使用du命令查看则不超过10个G. [root@shanghai devicemapper]# ls -l 总用量 -rwxr ...
- OTA升级常见问题
OTA升级常见问题 问题现象:在进行 OTA 升级测试时,下载成功了升级包,在点击立即更新后,手机一直处于提示“正在更新中”,没能重启进行升级. 问题分析:经过分析发现,因为OTA 应用不具备系统权限 ...
- npm install Error: EACCES: permission denied, mkdir
今天研究Electron的时候,全局安装运行 npm install electron -g时侯,报下面的错误: Error: EACCES: permission denied, mkdir '/U ...
- RFC2119 规范内容
RFC2119 https://www.ietf.org/rfc/rfc2119.txt Network Working Group S. Bradner Request for Comments: ...
- MySQL count
https://www.jianshu.com/p/1b0a1f641e80] 不同引擎count(*)实现方式不同 MyISAM引擎把一个表的总行数记录在了磁盘上,执行count(*)会直接返回这个 ...
- cordova添加plugin的多种方式
#在线安装 cordova create chankoujie com.example.chankoujie ChanKouJie cordova plugin add cordova-plugin- ...
- 【docker】 yaml.scanner.ScannerError: mapping values are not allowed here in "./docker-compose.yml", line 60, column 35
在启动docker-compose 时候 报错了 命令: docker-compose up -d && docker-compose logs -f 错误代码: 解决 出现这个错误的 ...