swagger配置及升级版swagger-bootstrap-ui配置+访问账号密码登录限制
本文主要介绍swagger-ui及加强版swagger-bootstrap-ui配置
一:普通swagger-ui配置
1:pom添加依赖
<!--swagger-->
<dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger2</artifactId><version>2.6.1</version>
</dependency>
<dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger-ui</artifactId><version>2.6.1</version>
</dependency>
2:添加配置类SwaggerConfig:
import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;@Configuration
@EnableSwagger2
public class SwaggerConfig {@Beanpublic Docket createRestApi() {return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().apis(RequestHandlerSelectors.basePackage("com.XXX.web.controller"))//扫描包范围.paths(PathSelectors.any()).build();}/*** API 说明,包含作者、简介、版本、host、服务URL*/private ApiInfo apiInfo() {return new ApiInfoBuilder().title("XXXAPI文档").description("XXXAPI文档")//.contact(new Contact("API文档", "http://www.XXX.com/", "xxx@qq.com"))//作者信息//.version("1.0")//定义api 版本号.build();}
}
3:如果有登录验证等拦截器,如下资源需要放行
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
4:Controller添加如下swagger 注解即可
//类注解:
@Api(tags = "1.0",value = "account",description = "账户Controller")//方法注解:@ApiOperation(value = "用户账户", notes = "提现列表",httpMethod = "POST")@ApiImplicitParam(name = "userId", value = "userId", required = true)
5:访问地址
ip:port/swagger-ui.html
1
二:加强版swagger-bootstrap-ui配置
swagger-bootstrap-ui相比swagger-ui更加强大,提供测试及账号密码验证登录等配置,个人觉得文档页面样式更加简洁明了
配置方式基本与swagger-ui一致
1:修改pom依赖
<!--swagger-->
<dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger2</artifactId><version>2.6.1</version>
</dependency>
<dependency><groupId>com.github.xiaoymin</groupId><artifactId>swagger-bootstrap-ui</artifactId><version>1.9.6</version>
</dependency>
2:添加配置类SwaggerConfig:在swagger-ui基础上只是多了@EnableSwaggerBootstrapUI类注解
import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class SwaggerConfig {@Beanpublic Docket createRestApi() {return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().apis(RequestHandlerSelectors.basePackage("com.XXX.web.controller"))//扫描包范围.paths(PathSelectors.any()).build();}/*** API 说明,包含作者、简介、版本、host、服务URL*/private ApiInfo apiInfo() {return new ApiInfoBuilder().title("XXXAPI文档").description("XXXAPI文档")//.contact(new Contact("API文档", "http://www.XXX.com/", "xxx@qq.com"))//作者信息//.version("1.0")//定义api 版本号.build();}
}
3:配置文件添加接口文档访问自定义账号密码(本文为yml格式)
#配置swagger登陆验证
swagger:production: falsebasic:enable: trueusername: xxxpassword: xxx
4:修改拦截器等放行资源
registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
5:访问地址
ip:port/doc.html
账号密码即为3中所配置username及password
swagger配置及升级版swagger-bootstrap-ui配置+访问账号密码登录限制相关推荐
- SpringBoot - 集成Swagger、Knif4j接口文档以及文档添加账号密码登录
文章目录 集成Swagger.Knif4j 依赖 配置 演示 集成Swagger.Knif4j 依赖 pom.xml <!-- 引入Knife4j的官方start包,Swagger2基于Spri ...
- springboot 整合 swagger2 配置账号密码登录 demo代码
配置spring security登录可参考: springboot整合spring security安全框架-简单验证账号密码 一.pom文件引入swagger依赖 <!-- swagger2 ...
- MongoDB学习2 - 账号密码登录、副本集配置
文章目录 1. 高级 1.1 用户账号密码登陆.集群机器使用Key文件 - 安全认证 1.1.1 概述 1.1.1.1 内置角色 - 用于普通用户登录 1.1.1.2 内置语法 - 用于普通用户登录 ...
- Docker的安装 与 环境配置 及 阿里云镜像仓库配置、常用命令等
目录 一.Docker简介 Docker的应用场景 Docker 的优点 1.简化程序 2.避免选择恐惧症 3.节省开支 Docker的架构 Docker 和虚拟机的区别 下图是虚拟机的体系结构: 下 ...
- 搭建网站服务器的配置要求,搭建网站服务器自己配置
搭建网站服务器自己配置 内容精选 换一换 您可以选择华为云搭建您的网站,华为云提供丰富的建站资源和建站方式,如表1所示. 实例即云耀云服务器,是由CPU.内存.操作系统.云硬盘组成的基础的计算组件.云 ...
- solr账号密码配置
solr默认情况下是没有配置登录账号密码的,在这种情况下存在安全隐患. 例如:可以 从cmd 命令执行curl http:// IP :8983/solr/admin/cores (或者浏览器访问)可 ...
- Swagger - 魔改版本的 bootstrap swagger UI 页面 ,springboot 集成
文章目录 Swagger - 魔改版本的 bootstrap swagger UI 页面 ,springboot 集成 1.快速开始 2.编写配置类 3.访问地址 4.权限相关 5.404 问题解决 ...
- 带有Swagger的Spring Rest API –集成和配置
如今,公开的API终于获得了应有的关注,公司也开始意识到其战略价值. 但是,使用第三方API确实是一项繁琐的工作,尤其是当这些API维护不当,设计不当或缺少任何文档时. 这就是为什么我决定四处寻找可以 ...
- java+swagger+侵入_Spring boot+Swagger配置无侵入式Restful接口(二)
maven依赖自动配置 额,看了前面第一种配置方式,是不是感觉有点麻烦呢?我也觉得,到时候去掉的时候,还需要进行删除配置啊,一大堆,还有可能到时候根本不知道. 所以,我决定自己写个让它自己就可以完成配 ...
最新文章
- 遍历矩阵每一行穷举_LeetCode:二维数组—旋转矩阵
- 更方便地模拟 Http 响应
- vbs当计算机重启,用vbs实现重新启动 Internet Explorer
- android 生命周期流程图,Android Studio ——Service的生命周期
- python的exe缺少dll_python错误py2exe(缺少DLL)
- bzoj 1689: [Usaco2005 Open] Muddy roads 泥泞的路(模拟)
- 最近碰到的一些 SSL 问题记录
- linux断点续传程序,Linux下怎么实现断点续传
- SpringBoot------拦截器Filter的使用
- 计算机编程告白,程序员的520,五个表白代码,一看就会
- tcl机顶盒 tk 8296刷机固件及教程
- AVC1与AVC与H264
- 每日一记—获取Bing每日一图实现Android欢迎页(一)
- 如何将.frm,.MYD,.MYI文件导入数据库
- 让假照片原形毕露?今日水印相机上线“照片验真”功能
- Google Maps谷歌地图车辆位置描点、位置详情查看
- 概率论02-概率,古典概型
- DevOps入门系列--前瞻性--前瞻性思维
- 题目6:求n阶方阵的和
- Unity游戏存档的四种方式
热门文章
- python的1e2与math.e的区别
- “称心如意”中。。。。。。。。。。。。。。
- Android入门第十六篇之Style与Theme
- Crontab执行java/spark-shell/spark-submit 异常解决方法
- 【AppCan 开发者第一期】Samlee:西北青年的移动开发梦
- 订单中心表结构设计_SAP 常用表 MM PP SD FICO PM PS QM WM 等
- 计算机相关知识点整理
- DirectX10 游戏的美好未来
- Java介绍、应用、前景
- 在IEEE TVCG模板使用bib文件加入参考文献