java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[?:1.8.0_242]
出現此錯誤,就是應該導入了多個版本的swagger依賴
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
通過IDEA提供的依賴圖查看,項目中存在 1.5.20版本和2.1.2版本,需要排除1.5.20版本的依賴;解決方法如下:替換swagger的依賴包即可
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-boot-starter</artifactId> <version>3.0.0</version> <exclusions> <exclusion> <artifactId>swagger-models</artifactId> <groupId>io.swagger</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-common</artifactId> <version>3.0.0</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-swagger2</artifactId> <version>3.0.0</version> <scope>compile</scope> <exclusions> <exclusion> <groupId>io.swagger</groupId> <artifactId>swagger-annotations</artifactId> </exclusion> <exclusion> <groupId>io.swagger</groupId> <artifactId>swagger-models</artifactId> </exclusion> </exclusions> </dependency>
因為
springfox-boot-starter:3.0 依賴導入了2個版本,所以只需要把低版本排除即可
其他問題:如果把1.5.20低版本給去掉的話,會報io.swagger.models依賴找不到
所以添加最新版1.6.2版本即可
<dependency> <groupId>io.swagger</groupId> <artifactId>swagger-models</artifactId> <version>1.6.2</version> </dependency> <dependency> <groupId>io.swagger</groupId> <artifactId>swagger-annotations</artifactId> <version>1.6.2</version> </dependency>
swagger快捷導航:
2. Swagger-code 2.0注解(基本不可用):大部分注解的屬性使用沒有效果 ,如@Schema里的description屬性沒有通過swagger api接口返回,頁面並未展示,還有其他坑
3. Swagger-Code 入門導航
Swagger2.0的注解不清楚為什么不起作用,有知道的朋友請在下方評論交流,網絡上基本都是介紹Swagger1.5.X的注解