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

相关推荐
知识即是力量ol11 小时前
微服务架构:从入门到进阶完全指南
java·spring cloud·微服务·nacos·架构·gateway·feign
j2001032215 小时前
Gateway—— 高级流量路由
gateway·k8s
笨蛋不要掉眼泪16 小时前
Spring Cloud Gateway 核心篇:深入解析过滤器(Filter)机制与实战
java·服务器·网络·后端·微服务·gateway
笨蛋不要掉眼泪16 小时前
Spring Cloud Gateway 扩展:全局跨域配置
java·分布式·微服务·架构·gateway
love530love3 天前
ZeroClaw Reflex UI完整搭建流程——ZeroClaw Gateway + LM Studio + Reflex 本地 AI 管理面板
人工智能·windows·gateway·lm studio·reflex·openclaw·zeroclaw
利刃大大5 天前
【SpringCloud】Gateway Filter Factories && 过滤器执行顺序 && 自定义过滤器
java·后端·网关·spring cloud·gateway
2401_834120875 天前
spring-cloud-kubernetes与SpringCloud Gateway
spring cloud·kubernetes·gateway
猫头虎5 天前
web开发常见问题解决方案大全:502/503 Bad Gateway/Connection reset/504 timed out/400 Bad Request/401 Unauthorized
运维·前端·nginx·http·https·gateway·openresty
Jinkxs5 天前
Gateway - 内置 Filter 使用指南:AddRequestHeader、RewritePath 等实战
gateway
利刃大大7 天前
【SpringCloud】网关GateWay && Spring Cloud Gateway && Route Predicate Factories
网关·spring·spring cloud·gateway