SpringBoot2.x系列教程(五十三)SpringBoot2.x集成swagger2配置权限认证参数Authorize

在使用swagger2时,如果api接口需要token等权限认证内容,那么此时可以有两种方案进行解决:方案一,每个请求上面都添加对应token的key和value值。方案二:全局统一添加权限认证的token。

一般情况下token都存放在header中。

引入swagger2依赖

引入对应的swagger2依赖:

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.9.2</version>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.9.2</version>
</dependency>

集成配置方案一

首先我们来看第一种方案,也就是每个请求都添加对应header信息,对应的config文件配置如下:

import com.google.common.collect.Lists;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.b

猜你喜欢

转载自blog.csdn.net/wo541075754/article/details/105097633