我想在 Spring Cloud Gateway 中為不同的 api 添加自定義路徑。我有兩個API:服務(wù)1:http://localhost:2121服務(wù) 1 的端點如下:http://localhost:2121/abc服務(wù)2:http://localhost:3434服務(wù) 2 的端點如下http://localhost:3434/abcAPI網(wǎng)關(guān):http://localhost:8090問題:我想將 service1 路徑添加到 API Gateway,并且我想重定向到服務(wù) 1示例 1:http://localhost:8090/service1/abc應(yīng)該重定向到http://localhost:2121/abc示例 2:http://localhost:8090/service1/anything應(yīng)該重定向到http://localhost:2121/anything服務(wù)2同樣的事情。我使用 Spring Cloud Gateway 的 yml 配置。spring: application: name: api-gateway cloud: gateway: routes: - id: service1 uri: http://localhost:2121 - id: service2 uri: http://localhost:3434提前致謝。
1 回答

繁星淼淼
TA貢獻1775條經(jīng)驗 獲得超11個贊
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
那么映射'/service1/xxxx'的所有請求將代理到service_1'/xxxx'。
添加回答
舉報
0/150
提交
取消