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. 【Codeforces 115D】Unambiguous Arithmetic Expression

    Codeforces 115 D 题意:给一个没有括号的表达式,问有多少种添加括号的方法使得这是一个合法的表达式?输入可能有正负号.加减乘除.数字. 思路1: 这是不能过的\(naive\)的\(dp ...

  2. TCP/IP协议--TCP的超时和重传

    TCP是可靠传输.可靠之一体现在收到数据后,返回去一个确认.但是不能完全避免的是,数据和确认都可能丢失.解决这个办法就是,提供一个发送的重传定时器:如果定时器溢出时还没收到确认,它就重传这个报文段. ...

  3. 一头雾水的"Follow The Pointer"

    原文:一头雾水的"Follow The Pointer" 一头雾水的"Follow The Pointer"                           ...

  4. [转]The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path

    完整错误信息: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS"AS IS" AND ANY ...

  5. 【php增删改查实例】第十三节 - EasyUI列格式化

    因为easyUI的datagrid组件是横着一格一格加载数据的,一行加载好了之后才会去加载下一行.所谓的列格式化,就是在加载某一列的所有单元格时,对即将加载到这些单元格的数据进行二次包装. 比如,我们 ...

  6. pandas:字段值插入数据表第一行的解决办法

    1. 问题描述 在对课程表进行数据抽取时,由于课表结构的原因,需要在原始表字段名作为第一行数据,并对原始字段名进行替换. 原始数据如下所示: 2. 解决办法 经思考,此问题可抽象为:在不影响原始数据的 ...

  7. 苹果企业账号打包发布App的详细流程

    原文链接:http://www.cnblogs.com/mddblog/p/4718228.html 一.通过企业账号申请证书 1 Certificate Signing Request (CSR)文 ...

  8. 案例学Python--案例四:Django实现一个网站的雏形(1)

    第一次用python的Web框架,也是第一次听说Django,参考菜鸡教程和一些博客,倒腾了半天,算是有一个雏形.数据基于昨天爬的豆瓣电影信息,详见案例三. Python版本:3.7.1 Django ...

  9. Bash Shebang 小结

    在 shell(Bash 是一种 shell) 中执行外部程序和脚本时,Linux 内核会启动一个新的进程,以便在新的进程中执行指定的程序或脚本.内核知道该如何为编译型的程序做这件事,但是对于脚本程序 ...

  10. Java Mongo 自定义序列化笔记

    从insert方法入手 1. org.springframework.data.mongodb.repository.support.SimpleMongoRepository.java   inse ...