Spring Cloud Gateway如何匹配某路径并进行路由转发

Spring Cloud Gateway如何匹配某路径并进行路由转发

本案例,将/helloworld-app/**的请求转发到helloworld微服务的/**路径(既如lb://helloworld/**)

配置如下(见spring.cloud.gateway.routes配置):

spring:
  application:
    name: SpringCloudGatewayDemo
  cloud:
    nacos:
      discovery:
        server-addr: localhost:8848
        namespace: b62b1132-d8c6-4740-b745-75bcfb4f66a5
        cluster-name: GD
    gateway:
      discovery:
        locator:
          # 让gateway通过服务发现组件找到其他的微服务
          enabled: true
      routes:
        - id: helloworld_route
          uri: lb://helloworld
          predicates:
            - Path=/helloworld-app/**
          filters:
            - RewritePath= /helloworld-app/(?<segment>.*), /${segment}
server:
  port: 8099
management:
  endpoints:
    web:
      exposure:
        include: '*'
  endpoint:
    health:
      show-details: always

转载请说明出处内容投诉
CSS教程网 » Spring Cloud Gateway如何匹配某路径并进行路由转发

发表评论

欢迎 访客 发表评论

一个令你着迷的主题!

查看演示 官网购买