SpringBoot整合Swagger

469 阅读1分钟

一、引入依赖

在pom文件引入依赖

<dependency>
    <groupId>com.spring4all</groupId>
    <artifactId>swagger-spring-boot-starter</artifactId>
    <version>1.9.0.RELEASE</version>
</dependency>

注:依赖版本可以自己选择

image.png

二、添加配置

这里直接在yml配置文件配置设置,无需再另外加配置文件

swagger:
  print-init: true
  enabled: true
  security-configuration:
    client-id: client-1
    client-secret: secretA
    scope-separator: \,
    use-basic-authentication-with-access-code-grant: true
  dockets:
    docket-api:
      base-package: 扫描的包的路径
      group-name: api
      api-info:
        title: 要展示的接口名称
        description: 接口描述
        version:版本号
        license: 版权
      global-parameters:
        - name: token
          description: Access Token
          param-type: header`

三、开启功能

在启动类加注解 @EnableSwagger2Doc 开启,如下所示

image.png

四、访问测试

访问默认链接 http://域名:端口/swagger-ui.html#/

image.png