spring-cloud-gateway - Spring Cloud Gateway 匹配多个路径元素
问题描述
Spring Cloud Greenwichspring-cloud-netflix-zuul
进入维护模式,所以我正在尝试从 Zuul 迁移到 Spring Cloud Gateway。
使用 Zuul,我有一条类似的路线
zuul:
routes:
masterplan_match:
path: /**/masterplans/**
serviceId: api-masterplan
我在那里所做的基本上是忽略masterplan
接收路径中之前或之后的所有内容并重定向到api-masterplan
. 例如,两者/some/path/to/masterplans
都/masterplans
使用同一个 api(原因是masterplans
更大实体的子资源,它负责创建新的masterplans
,但随后masterplans
可以被视为完整的资源,用于诸如GET
细节、更新、删除等目的)。
我可以将此配置映射到 Spring Cloud Gateway 吗?查看predicates,可行的似乎是path predicate,但看起来所有匹配器都在单个路径元素上工作(除了WildcardTheRestPathElement
,但它只能用作最后一个元素 - 我认为),即:我需要写就像是
spring
cloud:
gateway:
routes:
- id: masterplan_match
uri: lb://api-masterplan # Coming from discovery client
predicates:
- Path=/some/path/to/masterplans/**, /masterplans/**
我是否遗漏了一些东西,这两条路径可以浓缩成一条吗?
解决方案
Spring Cloud Gateway 自版本以来支持多种模式2.1.0
spring
cloud:
gateway:
routes:
- id: masterplan_match
uri: lb://api-masterplan # Coming from discovery client
predicates:
- Path=/some/path/to/masterplans/**, /masterplans/**
也可以看看:
推荐阅读
- html - 编辑器不想在网页上显示代码
- javascript - Firebase 云功能:onUpdate 更改参数错误去删除值
- apache-flink - 哪个版本稳定?
- python - 在 Linux 上安装 pyodbc 失败
- django - 管理视图中的 Django ImageField url 不正确
- php - 在 Woocommerce 的存档页面上获取特定产品属性的 slug 列表
- sql - PLSQL 中的错误 -
- cordova - Cordova ios [cordova-plugin-openwith-ios 插件] app myHandler 函数未执行
- javascript - 如何从nodejs中的外部url检索DOM对象
- java - 此 URL 不支持 HTTP 方法 GET WL 12.2.1 上的 Rest-full WS