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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章