# springboot-gateway-consul-swagger **Repository Path**: WeiLiWangKa_admin/springboot-gateway-consul-swagger ## Basic Information - **Project Name**: springboot-gateway-consul-swagger - **Description**: springboot+springcloudGateway+consul+swagger 实现注册中心+路由+api文档聚合 - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 4 - **Forks**: 2 - **Created**: 2019-04-29 - **Last Updated**: 2022-10-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # springboot-gateway-consul-swagger #### 介绍 springboot+springcloudGateway+consul+swagger 实现注册中心+路由+api文档聚合 #### 软件架构 组件版本说明: springboot 2.1.4.RELEASE springcloudGateway Greenwich.SR1 consul v1.4.4 swagger 2.9.2 四个组件都使用了最新的版本。 软件构建中需要注意的点: ① gateway是支持webflux不支持web的,所以工程中要排除spring-web,如果真的用到了,需要引入spring-webflux.由于这个特性需要自己提供一些URL在使用说明中注明。 ② 老生常谈的版本冲突问题:springboot和springcloud版本关系,G版是给2.1.X用的,F版是给2.0.X用的。 #### 安装教程 1. 安装consul 下载页:https://www.consul.io/downloads.html。下完成后解压到计算机目录下,解压成功后文件只有一个可执行命令。 执行consul agent -dev 访问http://localhost:8500 效果如下图: ![consul启动成功](https://gitee.com/uploads/images/2019/0429/175429_6a88372e_1499766.png "WechatIMG24.png") 2. 启动service-xx、service-yy、service-gateway项目。 其中service-xx、service-yy为平级测试项目中实现两个东西: ①集成swagger ②集成consul客户端并正常注册。 service-gateway为网关项目,实现三个东西: ①集成swagger ②集成consul客户端并正常注册 ③集成gateway网关服务,关于对swagger的改进,在使用说明中具体分析。 三个工程启动成功后查看consul界面效果图如下: ![三工程启动](https://gitee.com/uploads/images/2019/0429/175749_23ed11e4_1499766.png "2.png") 3. 访问gateway的swagger界面可在右上角切换注册的其他工程:http://localhost:8081/swagger-ui.html。如下图所示: ![最终效果图](https://gitee.com/uploads/images/2019/0429/180018_11ed35b1_1499766.png "3.png") #### 使用说明 gateway中有两个swagger关键文件,第一个是SwaggerResourcesProvider【资源提供者】重写了得到资源列表的方法,资源列表来自路由资源。上面有提到gateway由于不支持spring-webmvc需要自己提供些URL,这个体现在SwaggerHandler文件中为何?因为swagger-ui依赖spring-webmvc,所以导致swagger-ui是不能集成的。 #### 参与贡献 1. 方志鹏老师博客:https://blog.csdn.net/forezp/article/details/87273153