首先感谢一位博主的分享https://www.cnblogs.com/xiaohouzai/p/8886671.html

话不多说直接上图和代码

首先我们要有一个springcloud分布式项目

我就简单的一个eureka注册中心然后就是一个user用户然后当然就是zuul网关拉。

eureka的配置我就不多说了,我直接贴zuul网关和swagger的相关配置

zuul中的配置

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.3.2.RELEASE</version>
</dependency>
<--swagger2依赖-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>

zuul 的application.yml

#网关配置
zuul:
LogFilter: #自定义过滤器的名称
pre: #自定义过滤器类型
disable: true # 是否禁用false
prefix: /api/ #网关前缀如:http://localhost;8080/api/其他服务名
routes: #路由规则
user-server: #用户的服务名
path: /user/** #你定义的zuul网关名

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger.web.UiConfiguration;
import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration
@EnableSwagger2
public class SwaggerConfig { @Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo());
} private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("分布式某某系统")
.description("某某系统接口文档说明")
.termsOfServiceUrl("http://localhost:8081")
.contact(new Contact("vker", "", "6492178@gmail.com"))
.version("1.0")
.build();
} @Bean
UiConfiguration uiConfig() {
return new UiConfiguration(null, "list", "alpha", "schema",
UiConfiguration.Constants.DEFAULT_SUBMIT_METHODS, false, true, 60000L);
}
}
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import springfox.documentation.swagger.web.SwaggerResource;
import springfox.documentation.swagger.web.SwaggerResourcesProvider; import java.util.ArrayList;
import java.util.List; @Component
@Primary
public class DocumentationConfig implements SwaggerResourcesProvider { @Override
public List<SwaggerResource> get() {
List<SwaggerResource> resources = new ArrayList<>();
//第一个参数随便写,中间的参数是你zuul中application中的配置路径,第三是版本信息,随意
resources.add(swaggerResource("随便填", "/api/user/v2/api-docs", "2.0"));
return resources;
} private SwaggerResource swaggerResource(String name, String location, String version) {
SwaggerResource swaggerResource = new SwaggerResource();
swaggerResource.setName(name);
swaggerResource.setLocation(location);
swaggerResource.setSwaggerVersion(version);
return swaggerResource;
}
}

然后就是user的配置

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.3.2.RELEASE</version>
</dependency>
<--swagger2依赖-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
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 Swagger2Config {
@Bean
public Docket createRestApi(){
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
//为当前包下controller生成API文档
.apis(RequestHandlerSelectors.basePackage("com.cn.me.controller"))
//为有@Api注解的Controller生成API文档
// .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
//为有@ApiOperation注解的方法生成API文档
// .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
.paths(PathSelectors.any())
.build();
} private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("xxxxx")//自己定义标题
.description("部门、用户等接口")
.version("1.0")
.build();
}
}

springcloud zuul网关整合swagger2,swagger被拦截问题的更多相关文章

  1. SpringCloud Zuul网关的简单理解

    Zuul网关功能 请求路由.服务路由.请求过滤 请求路由 参数配置如下所示,所有能够配置path规则的请求,都会被zuul网关转发到对应的url上. zuul.routes.user-service. ...

  2. spring-cloud zuul网关

    API Gateway 是随着微服务(Microservice)这个概念一起兴起的一种架构模式,它用于解决微服务过于分散,没有一个统一的出入口进行流量管理的问题. 使用 Zuul 实现 API Gat ...

  3. SpringCloud zuul 网关限流分析

    最近项目中 spring cloud zuul 运用到限流功能,打算配置一下就直接使用,不过在压测与调优过程中遇到一些没有预测到的问题,附上排查与解析结果 yml.pom配置 强烈推荐,按最新gith ...

  4. SpringCloud Zuul网关超时

    最近在使用SpringCloudZuul网关时,报错"NUMBEROF_RETRIES_NEXTSERVER_EXCEEDED", 查询资料后,发现: ribbon.Connect ...

  5. springCloud Zuul网关

    1.springboot 仅2.0.x 支持,在此选择 2.0.7 2.新建Module eureka-zuul-client 3.导入依赖 <?xml version="1.0&qu ...

  6. springCloud zuul网关服务

    第一步:编写application.properties文件 spring.application.name=api-gateway server.port=5555 zuul.routes.user ...

  7. 创建swagger的springboot-stater,并在spring cloud zuul网关中引入

    Swagger 是一款RESTFUL接口的.基于YAML.JSON语言的文档在线自动生成.代码自动生成的工具. 通过在controller中添加注解,即可轻易实现代码文档化. Swagger提供ui界 ...

  8. 白话SpringCloud | 第十一章:路由网关(Zuul):利用swagger2聚合API文档

    前言 通过之前的两篇文章,可以简单的搭建一个路由网关了.而我们知道,现在都奉行前后端分离开发,前后端开发的沟通成本就增加了,所以一般上我们都是通过swagger进行api文档生成的.现在由于使用了统一 ...

  9. Spring Cloud Zuul 网关的分布式系统中整合Swagger(转)和 zuul跨域访问问题

    首先恭喜自己终于找对了努力的方向,很荣幸能在公司接触到微服务架构,也很高兴公司一个大佬哥们愿意带我,他技术确实很牛逼,我也很佩服他,前后端通吃,干了六年能有这样的水平.最近跟着在搞微服务架构,给我分配 ...

  10. springboot+cloud 学习(四)Zuul整合Swagger2

    前言 在微服务架构下,服务是分散的,怎么把所有服务接口整合到一起是我们需要关注的. 下面举例用zuul作为分布式系统的网关,同时使用swagger生成文档,想把整个系统的文档整合在同一个页面上来说明. ...

随机推荐

  1. 【深入浅出Spring原理及实战】「源码调试分析」结合DataSourceRegister深入分析ImportBeanDefinitionRegistrar的源码运作流程

    每日一句 人的一生中不可能会一帆风顺,总会遇到一些挫折,当你对生活失去了信心的时候,仔细的看一看.好好回想一下你所遇到的最美好的事情吧,那会让你感觉到生活的美好. 注入案例代码 如何通过实现Sprin ...

  2. 算法之SPFA的前置:Bellman-Ford算法

    SPFA 我们都知道一个叫SPFA的算法,它是用来计算单源最短路径的,但是,众所周知它不是很稳定,容易退化. SPFA是基于什么被提出的? 基于一个叫做Bellman-Ford的算法. Bellman ...

  3. Ubuntu玩机记录,让我破电脑又飞起来了

    写在前面 很早之前的电脑ThinkPad E440,一直没怎么用.最近整理了一下电脑的资料,全部备份到云盘.整理的过程感觉电脑很慢很慢,难受极了.整理完后,终于我要对它下手了! 我制作了启动U盘,把U ...

  4. mysql17-sql优化-慢查询日志

    1.什么是慢查询日志MySQL的慢查询日志是MySQL提供的一种日志记录,它用来记录在MySQL中响应时间超过阀值的语句,具体指运行时间超过long_query_time值的SQL,会被记录到慢查询日 ...

  5. 基于昇腾计算语言AscendCL开发AI推理应用

    摘要:本文介绍了昇腾计算语言AscendCL的基本概念,并以示例代码的形式介绍了如何基于AscendCL开发AI推理应用,最后配以实际的操作演示说明如何编译运行应用. 本文分享自华为云社区<基于 ...

  6. PopClip使用教程图文详解 2022.12亲测有效

    PopClip简介 PopClip mac版是Macos上一款增强型复制粘贴工具,当你选中文字后,PopClip会自动弹出复制.剪切.粘贴.搜索等等操作,除了复制粘贴外,PopClip还提供了很多的扩 ...

  7. P30_全局配置 - window - 下拉刷新

    window 全局开启下拉刷新功能 概念:下拉刷新是移动端的专有名词,指的是通过手指在屏幕上的下拉滑动操作,从而重新加载页面数据的行为. 设置步骤:app.json -> window -> ...

  8. 宇宙最强开发工具VScode简易手册

    VS Code 的全称是 Visual Studio Code,是一款开源的.免费的.跨平台的.高性能的.轻量级的代码编辑器.它在性能.语言支持.开源社区方面,都做得很不错,是这两年非常热门的一款开发 ...

  9. Windows QT程序配置删除网卡IP

    1.Windows下可在CMD控制终端使用Dos命令对指定网卡进行IP配置,需要使用管理员权限打开CMD终端 往网卡添加IP主要有以下两种方法: 方法1: netsh interface ip add ...

  10. 如何将项目打包成apk或exe程序

    一. 打包成exe 确认已经安装了pyinstaller,然后依次执行下面指令 pyinstaller -F setup.py 打包exe pyinstaller -F -w setup.py 不带控 ...