网关zuul整合多个微服务的swagger保姆级教学

背景:

在前后端分离的大趋势下,swagger这种强大RESTful API文档在前端开发与后端开发的联调过程中有着不可或缺的作用。由于一个微服务体系里面往往存在多个微服务,正常我们访问其中一个微服务的swagger文档的路径格式是:ip+port/doc.html。但是如果我们每看一个微服务的API文档都需要切换ip和端口,就变得比较麻烦。于是在这里小编给大家整理一份在网关zuul整合一个微服务体系下的所有swagger文档教程。

一 springboot整合swagger

首先需要在每个微服务配置swagger的相应配置。比如第一步我们需要引入swagger的依赖。

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.9.2</version>
    </dependency>
    <dependency>
        <groupId>com.github.xiaoymin</groupId>
        <artifactId>swagger-bootstrap-ui</artifactId>
        <version>1.9.6</version>
    </dependency>

接下来我们需要添加配置类


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

/**
 * swagger配置类
 *
 * @author mark
 * @date 2022年12月10日 11:37:07
 */

/*@Profile({"dev", "test"}) // 仅本地测试、测试环境
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值