Swagger2异常 java.lang.NumberFormatException: For input string: ""
2024-10-19 16:43:33
问题
在访问swagger首页时报错:
java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Long.parseLong(Long.java:601)
at java.lang.Long.valueOf(Long.java:803)
at io.swagger.models.parameters.AbstractSerializableParameter.getExample(AbstractSerializableParameter.java:412)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:687)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:719)
报错的版本是2.9.2,2.7.0的版本是不报错的,2.8的版本也不会
我的依赖是这样的
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<!-- <version>2.7.0</version>-->
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<!-- <version>2.7.0</version>-->
<version>2.9.2</version>
</dependency>
原因
AbstractSerializableParameter.class
默认值为"",如果没有@ApiModelProperty(value = "id",example = "123")设置example值,则会出现上面异常
解决
修改swagger-models版本,1.5.21进行了修复
pom.xml文件修改为
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</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-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.21</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
<version>1.5.21</version>
</dependency>
或者是选择降低版本,使用2.7或者2.8
最新文章
- 代码的坏味道(14)——重复代码(Duplicate Code)
- CSS实现图片缩放特效
- 又一个半成品库 weblog rpc client
- 15个jQuery小技巧
- IntentService源码分析
- CoordinatorLayout 自定义Behavior并不难,由简到难手把手带你飞
- [poj2777] Count Color (线段树 + 位运算) (水题)
- c++ 递归斐波那契算法及时间复杂度
- Oracle.ManagedDataAccessDTC.dll 使用
- Pyhton开发【第五篇】:Python基础之杂货铺
- My.Ioc 代码示例——使用观察者机制捕获注册项状态的变化
- 10分钟精通SharePoint - SharePoint拓扑结构
- js操作文章、字符串换行
- [JavaScript] 表单验证不通过不提交的JS写法
- 2019.03.29 NOIP训练 友好国度(点分治+容斥)
- 微信小程序 table 简单测试
- c++入门之初话结构体
- Django(十二)—关于查询知识点总结
- vim自动添加tags、cscope
- Java服务端单元测试指南
热门文章
- reorder-list leetcode C++
- Spoj 2878 KNIGHTS - Knights of the Round Table | 双联通分量 二分图判定
- poj 3041 Asteroids(最小点覆盖)
- Access的分页代码
- WPF进阶技巧和实战03-控件(4-基于范围的控件及日期控件)
- C++ STL的一些应用
- JVM 核心参数
- 执行对象Statement、PreparedStatement和CallableStatement详解
- 96.n-1位数
- 逐浪CMS+百度小程序开源包发布-对接海量资源助力推广