【问题标题】:What's the use of matchOptionalTrailingSeparator in Spring Cloud Gateway PredicateSpring Cloud Gateway Predicate中matchOptionalTrailingSeparator有什么用
【发布时间】:2020-10-11 01:38:04
【问题描述】:

来自 Spring.io 给出的关于 Spring Cloud 的文档:

路径路由谓词工厂有两个参数:一个 Spring PathMatcher 模式列表和一个名为 matchOptionalTrailingSeparator 的可选标志。

它提到了一个可选标志matchOptionalTrailingSeparator,没有更多描述。

这个标志有什么用以及如何使用这个标志? 谢谢

【问题讨论】:

  • 如果我的回答解决了您的问题,那么您应该投票并接受答案,以便任何面临类似问题的人都知道以下解决方案解决了原始问题

标签: spring spring-cloud spring-cloud-gateway


【解决方案1】:

参数matchOptionalTrailingSeparator 用于确定给定的Path 谓词是否也应该匹配带有尾部斜杠/ 的请求。 默认情况下,this 的值为true

例如路线下方

spring:
  cloud:
    gateway:
      routes:
      - id: host_route
        uri: https://example.org
        predicates:
        - Path=/foo/{segment}

将匹配请求/foo/{segment}/foo/{segment}/

但如果写成:

spring:
  cloud:
    gateway:
      routes:
      - id: host_route
        uri: https://example.org
        predicates:
        - Path=/foo/{segment},false

它不会匹配带有斜杠/的请求,即它只会匹配/foo/{segment}而不匹配/foo/{segment}/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-23
    • 2020-07-31
    • 1970-01-01
    • 1970-01-01
    • 2022-08-16
    • 2021-04-02
    • 2021-10-20
    • 1970-01-01
    相关资源
    最近更新 更多