接口文档管理工具(Swagger+knife4j)

1、Swagger快速入门

1.1 swagger介绍

官网:https://swagger.io/
接口文档管理工具(Swagger+knife4j)_第1张图片
Swagger 是一个规范和完整的Web API框架,用于生成、描述、调用和可视化 RESTful 风格的 Web 服务。

功能主要包含以下几点:
A. 使得前后端分离开发更加方便,有利于团队协作;
B. 接口文档在线自动生成,降低后端开发人员编写接口文档的负担;
C. 接口功能测试;

使用Swagger只需要按照它的规范去定义接口及接口相关的信息,再通过Swagger衍生出来的一系列项目和工具,就可以做到生成各种格式的接口文档,以及在线接口调试页面等等;

1.2 项目集成swagger流程

  • 引入swagger依赖;
    - 定义swagger配置类;
    - swagger扫描管理的web资源路径;
    - 配置项目文档标题、描述、版本等信息、官网地址等信息;
    - 通过swagger注解给指定资源添加描述信息;
    - 项目启动,访问并测试在线资源;

1.3 项目集成swagger

在stock_common工程引入依赖

  io.springfox
  springfox-swagger2
  2.9.2


  io.springfox
  springfox-swagger-ui
  2.9.2

在stock_common工程config包定义swagger配置类
package com.itheima.stock.config;
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documenta

你可能感兴趣的:(swagger,knife4j,java,spring,boot)