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 利用属ObjectAnimator,AnimatorSet性动画绘制一个弹球,加速下落,到底部时挤压,然后减速上弹

    属性动画主要的几个类介绍: 1.ValueAnimator:这个类提供了一个简单的计时引擎运行动画动画计算值和设置目标对象.注意:使用该类时一般都是用:ObjectAnimator,而基于Object ...

  2. linux调度器源码分析 - 运行(四)

    本文为原创,转载请注明:http://www.cnblogs.com/tolimit/ 引言 之前的文章已经将调度器的数据结构.初始化.加入进程都进行了分析,这篇文章将主要说明调度器是如何在程序稳定运 ...

  3. [05] Bean的作用域和生命周期

    1.Bean的作用域和初始化时间 之前我们稍微提到过,Spring中管理的Bean,默认都是单例模式,这意味着你多次获取某个对象,得到的都是相同的对象.单例作用域的显性写法是scope属性,如下,这和 ...

  4. jquery $.each()遍历json数组

    使用jQuery的$.each()方法来遍历一个数组对象 var json=[ {"id":"1","tagName":"appl ...

  5. 面试2——java基础3

    21.Http请求的get和post的区别? get:从 指定的资源请求数据.请注意,查询字符串(名称/值对)是在 GET 请求的 URL 中发送的 post:向指定的资源提交要被处理的数据.请注意, ...

  6. myeclipse、maven、tomcat、jdk技巧和坑【待完善】

    公司使用前后不分离或半分离的springmvc + maven ,自己不得不研究研究myeclipse.maven.tomcat等等 开发环境搭建:坑一: Unable to process Jar ...

  7. item 8: 比起0和NULL更偏爱nullptr

    本文翻译自modern effective C++,由于水平有限,故无法保证翻译完全正确,欢迎指出错误.谢谢! 博客已经迁移到这里啦 先让我们看一些概念:字面上的0是一个int,不是一个指针.如果C+ ...

  8. ExtJS初探:在项目中使用ExtJS

    注意:本文写作时间是 2013 年,所讲的 ExtJS 如今早已过时,请勿学习! -------------------------------- 今天ExtJS官网发布了ExtJS最新正式版4.2. ...

  9. Webpack 2 视频教程 001 - Webpack 简介

    这是我免费发布的高质量超清「Webpack 2 视频教程」. Webpack 作为目前前端开发必备的框架,Webpack 发布了 2.0 版本,此视频就是基于 2.0 的版本讲解的. 这个基本就是目前 ...

  10. SpringCloud设定Feign底层实现

    1. 概述 版本: spring-boot:  1.5.9.RELEASE spring-cloud: Dalston.SR5 在默认情况下 spring cloud feign在进行各个子服务之间的 ...