亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在Spring Cloud Gateway中添加額外的路徑到uri

如何在Spring Cloud Gateway中添加額外的路徑到uri

Smart貓小萌 2024-01-05 10:21:56
我想在 Spring Cloud Gateway 中為不同的 api 添加自定義路徑。我有兩個API:服務1:http://localhost:2121服務 1 的端點如下:http://localhost:2121/abc服務2:http://localhost:3434服務 2 的端點如下http://localhost:3434/abcAPI網關:http://localhost:8090問題:我想將 service1 路徑添加到 API Gateway,并且我想重定向到服務 1示例 1:http://localhost:8090/service1/abc應該重定向到http://localhost:2121/abc示例 2:http://localhost:8090/service1/anything應該重定向到http://localhost:2121/anything服務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條經驗 獲得超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'。

查看完整回答
反對 回復 2024-01-05
  • 1 回答
  • 0 關注
  • 246 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號