【问题标题】:Spring Cloud Gateway: why route uri property ignored?Spring Cloud Gateway:为什么忽略路由uri属性?
【发布时间】:2022-08-16 23:09:18
【问题描述】:

我只有这条路线

spring.cloud.gateway.routes[0].id=x-service
spring.cloud.gateway.routes[0].uri=http://localhost:5555/x-service/v1/private/files
spring.cloud.gateway.routes[0].predicates[0]=Path=/v1/private/files

但应用重定向到/v1/private/files

如何解决这个问题?

    标签: spring spring-cloud-gateway


    【解决方案1】:

    AFAIK spring-cloud-gateway Route builder 只考虑传递给UriSpec.uri(String uri) 的主机名和端口,因此此时只有http://localhost:5555 很重要。

    所以你需要重写你的路径,使用RewritePath 网关过滤器,如下所示:

    spring.cloud.gateway.routes[0].filters[0]=RewritePath=/v1/private/files, /x-service/v1/private/files
    

    第一个参数是原始路径,第二个参数是替换器。
    RegEx 也可以在那里使用。

    详情请查看spring-cloud-gateway reference docs
    另外我建议阅读this article

    【讨论】:

      猜你喜欢
      • 2023-04-02
      • 2019-08-03
      • 2019-03-31
      • 2021-03-11
      • 2023-01-21
      • 2017-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多