如何在春季云通道中向uri添加额外的路径

问题描述 投票:0回答:1

我想在Spring Cloud Gateway中为不同的api添加自定义路径。

我有两个API:

  1. Service1:http://localhost:2121

服务1的端点类似于:http://localhost:2121/abc

  1. Service2:http://localhost:3434

服务2的端点类似于http://localhost:3434/abc

api网关:http://localhost:8090

问题:

我想将service1路径添加到API网关,并且我想重定向到服务1

示例1:http://localhost:8090/service1/abc应该重定向到http://localhost:2121/abc

示例2:http://localhost:8090/service1/anything应该重定向到http://localhost:2121/anything

与服务2相同。

我将yml配置用于Spring Cloud Gateway。

spring:
  application:
    name: api-gateway
  cloud:
    gateway:
      routes:
        - id: service1
          uri: http://localhost:2121
        - id: service2
          uri: http://localhost:3434

提前感谢。

java spring cloud gateway
1个回答
0
投票
spring:
    cloud:
        gateway:
            routes:
            -  id: service1
               uri: http://localhost:2121
               predicates:
               -   Path=/service1/**
               filters:
               -   StripPrefix=1
            -  id: service2
               uri: http://localhost:3434
               predicates:
               -   Path=/service2/**
               filters:
               -   StripPrefix=1
© www.soinside.com 2019 - 2024. All rights reserved.