在使用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