我想在Spring Cloud Gateway中为不同的api添加自定义路径。
我有两个API:
http://localhost:2121
服务1的端点类似于:http://localhost:2121/abc
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
提前感谢。
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