1. 每个请求都需要换取key:

@Bean
public Docket createRestApi() {
//添加head参数start
ParameterBuilder appId = new ParameterBuilder();
ParameterBuilder tokenCode = new ParameterBuilder();
List<Parameter> pars = new ArrayList<Parameter>();
appId.name("AppId").description("客户端编号").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
tokenCode.name("AppToken").description("Token令牌").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
pars.add(appId.build());
pars.add(tokenCode.build());
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.inuo.project.tool.swagger"))
.paths(PathSelectors.any()).build()
.globalOperationParameters(pars)
// 详细定制
.apiInfo(apiInfo());
} /**
* 添加摘要信息
*/
private ApiInfo apiInfo() {
// 用ApiInfoBuilder进行定制
return new ApiInfoBuilder().title("标题:XX管理系统_接口文档").description("描述:用于管理集团旗下公司的人员信息,具体包括XXX,XXX模块...")
.contact(new Contact(inuoConfig.getName(), null, null)).version("版本号:" + inuoConfig.getVersion())
.build();
}

  

2. 全局Key

@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).
useDefaultResponseMessages(false)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.regex("^(?!auth).*$"))
.build()
.securitySchemes(securitySchemes())
.securityContexts(securityContexts())
;
}
private List<ApiKey> securitySchemes() {
List<ApiKey> list = new ArrayList<ApiKey>();
ApiKey ak = new ApiKey("Authorization", "Authorization", "header");
list.add(ak);
return list;
}
private List<SecurityContext> securityContexts() {
List<SecurityContext> list = new ArrayList<SecurityContext>();
SecurityContext sc = SecurityContext.builder().securityReferences(defaultAuth()).forPaths(PathSelectors.regex("^(?!auth).*$")).build();
list.add(sc);
return list;
} List<SecurityReference> defaultAuth() {
AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
authorizationScopes[0] = authorizationScope;
List<SecurityReference> list = new ArrayList<SecurityReference>();
SecurityReference sr = new SecurityReference("Authorization", authorizationScopes);
list.add(sr);
return list;
}

  

Swagger2 配置的更多相关文章

  1. Swagger2配置

    配置类 package top.yalong; import org.springframework.beans.factory.annotation.Value; import org.spring ...

  2. Swagger2配置与使用

    Swagger2配置与使用 Swagger2介绍 前后端分离开发模式中,api文档是最好的沟通方式. Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 We ...

  3. springboot新增swagger2配置

    转自http://www.cnblogs.com/jtlgb/p/8532433.html SpringBoot整合Swagger2 相信各位在公司写API文档数量应该不少,当然如果你还处在自己一个人 ...

  4. swagger2配置和使用

    1.导入swagger2 <dependency> <groupId>io.springfox</groupId> <artifactId>spring ...

  5. 使用swagger2配置springboot时出现的问题

    这个问题踩了几次坑了,这次又遇到了,不记录一下看来是不长记性了: 测试普通的增删改查的时候,发现删除和查询是对的,可是增加和更新却数据绑定不到controller的参数上面去. 因为是自定义的实体类, ...

  6. swagger2配置详解

    1.写在controller上的注解 1.1 @Api 代码 @Api(tags = "用户相关接口", description = "提供用户相关的 Rest API& ...

  7. spring clould -多模块 -swagger2 配置 nginx 的正确设置

    #user nobody; worker_processes 2; #error_log logs/error.log; #error_log logs/error.log notice; #erro ...

  8. SpringBoot集成Swagger2并配置多个包路径扫描

    1. 简介   随着现在主流的前后端分离模式开发越来越成熟,接口文档的编写和规范是一件非常重要的事.简单的项目来说,对应的controller在一个包路径下,因此在Swagger配置参数时只需要配置一 ...

  9. Spring Boot中使用Swagger2构建强大的RESTful API文档

    由于Spring Boot能够快速开发.便捷部署等特性,相信有很大一部分Spring Boot的用户会用来构建RESTful API.而我们构建RESTful API的目的通常都是由于多终端的原因,这 ...

随机推荐

  1. android.view.WindowManager$BadTokenException: Unable to add window

    这是在加载dialog时出现的一个异常.转载地址:http://hi.baidu.com/fbdfp/item/7dea2d0ade9121813d42e23d 扔了好久的android又开始断断续续 ...

  2. Luogu3199 HNOI2009 最小圈 分数规划、SPFA

    传送门 可以发现它的式子是一个分数规划的式子,所以可以二分答案,将所有边权减掉当前二分值之后跑一边$SPFA$判断负环即可. 然而这道题把$BFS-SPFA$卡掉了却没卡$DFS-SPFA$ 出题人: ...

  3. Luogu4423 BJWC2011 最小三角形 平面最近点对

    传送门 题意:给出$N$个点,求其中周长最小的三角形(共线的也计算在内).$N \leq 2 \times 10^5$ 这道题唤起了我对平面最近点对的依稀记忆 考虑平面最近点对的分治,将分界线两边的求 ...

  4. Luogu4139 上帝与集合的正确用法 拓展欧拉定理

    传送门 题意:求$2^{2^{2^{2^{...}}}} \mod p$的值.$p \leq 10^7$ 最开始想到的是$x \equiv x^2 \mod p$,然后发现不会做... 我们可以想到拓 ...

  5. Ionic 动态配置url路由的设置

    随着Ionic App功能的不断增加,需要路由的url设置就越来越多,不喜欢在config函数中写一堆硬代码,一则不美,二则维护起来也麻烦,能不能把这些数据独立出来呢? 经过查找资料与各种实验,最终找 ...

  6. 学习ML.NET(2): 使用模型进行预测

    训练模型 在上一篇文章中,我们已经通过LearningPipeline训练好了一个“鸢尾花瓣预测”模型, var model = pipeline.Train<IrisData, IrisPre ...

  7. Hybrid小程序混合开发之路 - 数据交互

    HTML+CSS是历史悠久.超高自由度.控制精准.表现能力极强.编码简单.学习门槛超低.真跨平台的一种UI界面开发方式. 本文介绍的是微信小程序和H5混合开发的一种数据交互方式. 很多应用在原生界面中 ...

  8. testNG-失败用例重跑方法探究

    实现IRetryAnalyzer类,重写其中的retry方法public class TestNGRetry implements IRetryAnalyzer { private int retry ...

  9. Dethe is my Finaunce金融

    英国诗人乔叟Dethe is my Finaunce金融 英语中“金融”在14世纪,金融计算时间价值的手段.就随机结果签约的能力.一个允许转让金融权后的清算.<Lamentation of Ma ...

  10. OneZero第一次随感

    >本人基础薄弱,有幸加入这个团队,甚感欣慰.这是本人第一次尝试写博客,说实话,胆怯.因为能力有限,怕技能匮乏,说不好.但是我知道既然加入这个团队,就要为团队负责.万事开头难,过程也挺难(就我个人 ...