swagger(2.9.2版本)报错 For input string: ““,的问题与 解决方法

问题:

swagger 的 2.9.2 版本内部默认依赖的是:

  • swagger-annotations:1.5.20

  • swagger-models:1.5.20

但这个版本在部分场景(比如和 Spring Boot 2.x / springfox-bootstrap-ui 等)集成时,可能存在以下问题:

💥 常见报错场景

  1. Swagger UI 加载失败,控制台报错:

    swagger For input string: ""

    说明有字段被错误地序列化为 "" 空字符串,而旧版本不兼容这种格式。

  2. 某些注解不生效,比如 @ApiModelProperty,导致生成文档缺字段。

  3. 与 swagger-bootstrap-ui 插件版本不兼容。

解决的代码:

  <!-- 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.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>
        <!-- 用于解决刷新 swagger-ui 页面,控制台报错 swagger For input string: "" 的问题 -->
        <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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值