今天使用swagger-ui.html访问时后台报错:java.lang.NumberFormatException: For input string: "".
具体原因是由于我pom引入的io.springfox:springfox-swagger-ui:2.92版本的jar包内置为io.swagger:swagger-models包为1.5.20版本.
1.5.20版本中判断example只判断是否为null,没有判断example为空字符串""的情况所以报错.1.5.21版本新增了判断example是否为null和"".所以排除1.5.20包重新导入1.5.21包即可解决.解决方案如下:
<!-- swagger2-UI--> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.9.2</version> <exclusions> <exclusion> <groupId>io.swagger</groupId> <artifactId>swagger-models</artifactId> </exclusion> </exclusions> </dependency> <!-- io.springfox:springfox-swagger2:2.9.2中依赖了swagger-models的1.5.20版本,通过排除springfox-swagger2中的swagger-models依赖, 导入io.swagger:swagger-models的1.5.21版本.解决io.swagger.models.parameters.AbstractSerializableParameter实例化参数时example为 空字符串""而报错的问题.因为1.5.20的example只判断是否为null,1.5.21判断了是否为null和""--> <dependency> <groupId>io.swagger</groupId> <artifactId>swagger-models</artifactId> <version>1.5.21</version> </dependency>