一、问题描述
项目启动,刷新Swagger web界面抛:java.lang.NumberFormatException: For input string: “”
出现的原因是在该swagger版本下对于数字类型的字段没有设置example值,导致swagger处理时类型转换异常,算是swagger-models1.5.20的一个小bug
二、解决方案分析
2.1、手动添加example值(费时费力不推荐)
为每个数字类型的字段或参数添加上example值
2.2、导入1.5.21版本的swagger-models(推荐)
排除springfox-swagger2中的swagger-models依赖,导入io.swagger:swagger-models的1.5.21版本即可。
<!-- swagger -->
<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.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>
<!-- doc.html模式 -->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.6</version>
</dependency>
注:以上内容仅提供参考和交流,请勿用于商业用途,如有侵权联系本人删除!