Spring Cloud Greenwich将spring-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
都使用同一个接口(原因是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/**
我是不是遗漏了什么,这两条路径能被压缩成一条吗?
发布于 2021-01-02 13:07:14
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/**
另请参阅:
https://stackoverflow.com/questions/54361071
复制