赞
踩
之前我们测试接口,都是使用 postman 工具,而 Swagger2 给出了测试接口的文档,使用方式如下:
1、添加依赖:
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.6</version>
</dependency>
2、浏览器访问:localhost:项目启动的端口/doc.html
报错: 可以正常访问,但是 IDEA 报错:java.lang.NumberFormatException: For input string: ""
分析: 该 Swagger 版本下对于数字类型的字段没有设置 example 值,导致 Swagger 处理时类型转换异常,算是swagger-models 1.5.20
的一个小 bug:
解决: 排除 springfox-swagger2 中的 swagger-models 依赖,导入 swagger-models1.5.21版本(或者1.5.22)即可:
<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>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。