一、问题描述
项目启动,刷新Swagger web界面抛:java.lang.NumberFormatException: For input string: “”
出现的原因是在该swagger版本下对于数字类型的字段没有设置example值,导致swagger处理时类型转换异常,算是swagger-models1.5.20的一个小bug
二、解决方案方法
导入1.5.21版本的swagger-models
排除springfox-swagger2中的swagger-models依赖,导入io.swagger:swagger-models的1.5.21版本就行了
<!-- swagger依赖-->
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<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>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>