在使用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.d
个人公众号【程序新视界】,一个硬技术,软实力同步提升的平台。《Spring Boo技术内幕:架构设计与实现原理》作者,《深入以太坊智能合约开发》联合作者之一。主要从事于三方支付行业。