Swagger的Starter使用及增强

  Swagger3.0 官方已经有了自己的 Spring Boot Starter,只需要添加一个 jar 包即可(SpringBoot 版本 2.3.6.RELEASE,低版本的SpringBoot要处理很多兼容性的问题)。。

        <dependency>
            <groupId>com.github.xiaoymin</groupId>
            <artifactId>knife4j-spring-boot-starter</artifactId>
            <version>3.0.2</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
            <version>3.0.0</version>
        </dependency>

  需要引用这2个包,springfox-boot-starter就是Swagger的Starter,knife4j-spring-boot-starter是Swagger-Bootstrap-UI的最新版本

  Swagger-Bootstrap-UI的中文文档地址:https://doc.xiaominfo.com/    开源地址:https://github.com/xiaoymin/Swagger-Bootstrap-UI

  Swagger的注解和配置都是旧版本保持一致。

  配置完之后,启动项目,访问地址:http://ip:port/doc.html

  相关文档:https://mp.weixin.qq.com/s/-yTe0N5mwN2JJyPg-MOSVQ

          https://mp.weixin.qq.com/s/Su33QhBRKnzwuNgTdriaTA

  注意:以上两个Starter包中引用的swagger-model、swagger-core、swagger-annotations 的版本是1.5.20和1.5.22版本,在访问页面时,还会出现空字段报错的问题。建议手动在maven中剔除,更新1.6.1以上版本的jar包。

原文地址:https://www.cnblogs.com/huanshilang/p/14143946.html