gateway 聚合了不同服务的swagger

gateway -- pom.xml

java 复制代码
  <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-gateway</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>com.github.xiaoymin</groupId>
            <artifactId>knife4j-gateway-spring-boot-starter</artifactId>
            <version>4.2.0</version>
        </dependency>
    </dependencies>

gateway -- application.xml

java 复制代码
server:
  port: 7777
  servlet:
    context-path: /
spring:
  application:
    name: gateway-server
  cloud:
    gateway:
      discovery:
        locator:
          enabled: true   #开启Eureka服务发现
          lower-case-service-id: true
      routes:
        - id: order-product
          uri: lb://order-product
          predicates:
            - Path=/order/**
        - id: user-consumer
          uri: lb://user-consumer
          predicates:
            - Path=/user/**
eureka:
  client:
    register-with-eureka: true
    fetch-registry: true
    service-url:
      defaultZone: http://localhost:7001/eureka/

knife4j:
  # 聚合swagger文档
  gateway:
    enabled: true
    # 排序规则(tag/operation排序自4.2.0版本新增)
    # 取值:alpha-默认排序规则,官方swagger-ui默认实现,order-Knife4j提供的增强排序规则,开发者可扩展x-order,根据数值来自定义排序
    tags-sorter: order
    operations-sorter: order
    # 指定手动配置的模式(默认为该模式)
    strategy: manual
    routes:
      - name: 用户服务
        # 真实子服务访问url地址-提供OpenAPI的文档
        url: /user/v2/api-docs?group=consumer_Group_1
        service-name: USER-CONSUMER
        # 路由前缀
        # 兼容OpenAPI3规范在聚合时丢失contextPath属性的异常情况,由开发者自己配置contextPath,Knife4j的前端Ui做兼容处理,与url属性独立不冲突,仅OpenAPI3规范聚合需要,OpenAPI2规范不需要设置此属性,默认为(apiPathPrefix)
        context-path: /user
        order: 1
      - name: 订单服务
        url: /order/v2/api-docs?group=provider_Group_1
        service-name: ORDER-PRODUCT
        # 路由前缀
        context-path: /order
        order: 2

效果 gateway 聚合了不同服务的swagger

相关推荐
疯狂的维修1 天前
关于Gateway configration studio软件配置网关
网络协议·c#·自动化·gateway
hadage2331 天前
--- 统一请求入口 Gateway ---
gateway
波波烤鸭3 天前
深入理解 Gateway 网关:原理、源码解析与最佳实践
java·spring·gateway
DO_Community3 天前
DigitalOcean Kubernetes 现已支持 Gateway API 托管服务
容器·kubernetes·gateway
T_Ghost3 天前
SpringCloud微服务网关Gateway
spring cloud·微服务·gateway
Rysxt_5 天前
Spring Boot Gateway 教程:从入门到精通
spring boot·网关·gateway
月夕·花晨5 天前
Gateway -网关
java·服务器·分布式·后端·spring cloud·微服务·gateway
sanggou6 天前
License 集成 Spring Gateway:解决 WebFlux 非阻塞与 Spring MVC Servlet 阻塞兼容问题
spring·gateway·mvc
摘星编程12 天前
Nginx 502 Bad Gateway:从 upstream 日志到 FastCGI 超时复盘
网络·nginx·gateway·php-fpm·fastcgi
网硕互联的小客服12 天前
504 Gateway Timeout:服务器作为网关或代理时未能及时获得响应如何处理?
运维·服务器·gateway