【问题标题】:spring-cloud-gateway path route predicate don't accept "/"spring-cloud-gateway 路径路由谓词不接受“/”
【发布时间】:2020-12-15 12:13:34
【问题描述】:

我有一个自定义网关过滤器,它使用 application.yml 中编写的路由, 当我想将路由谓词从 /test/myTest 更改为 /public 时,请求返回 404 似乎就像“/”没有重新调整,因为我试图将 /test-myTest 更改为 /public 并且它的工作。

请知道如何使用这种格式的谓词 /name/name/**

这是我的 application.yml :

myTest-gateway:
default-uri: https://app
apps:
  /test/myTest: mymicroservice-name
spring:
  cloud:
   gateway:
     enabled: false
     x-forwarded:
      proto-enabled: false 
     routes:
      - id: appsPrefixPathPublic
         uri: ${myTest-gateway.default-uri}
         predicates:
           - AppPath=/test/myTest
         filters:
          - StripPrefix=1
          - PrefixPath=/public

这是我得到的错误:

没有内容

{"timestamp":"2020-08-26T15:44:12.023+0000","path":"/test/myTest/whatever","status":404,"error":"不是 找到","message":null,"requestId":"e7baeeeb-6"}

java.lang.AssertionError:预期状态: 但原为:

【问题讨论】:

  • 请注意,您应该使用反引号保护 URL;看来您的问题可能没有正确显示。

标签: java spring-boot spring-cloud-config spring-cloud-gateway


【解决方案1】:

来自documentation

spring:
  cloud:
    gateway:
      routes:
      - id: nameRoot
        uri: https://nameservice
        predicates:
        - Path=/name/**
        filters:
        - StripPrefix=2

当通过网关向/name/blue/red 发出请求时,向nameservice 发出的请求看起来像nameservice/red

你应该把 1 改成 2。

【讨论】:

    猜你喜欢
    • 2023-01-21
    • 2019-06-10
    • 2019-09-16
    • 2019-08-03
    • 2019-03-31
    • 2020-06-01
    • 2021-11-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多