【问题标题】:Spring Gateway builds incorrect URL with query string parametersSpring Gateway 使用查询字符串参数构建不正确的 URL
【发布时间】:2021-06-04 11:59:21
【问题描述】:

我有一个带有此映射的 Spring 网关微服务:

  - id: advertisementService4
    uri: lb://advertisementService
    predicates:
      - Path=/public/breeds/**
    filters:
      - RewritePath=/public/breeds/(?<segment>/?.*), /v1/public/breeds/$\{segment}

如果我通过 Postman 调用此 url:http://192.168.99.1:8050/public/breeds/500,gateWay 服务会解决映射并以正确的方式构建新的 url(到 /v1/public/breeds/500):

但是如果我调用这个 url http://192.168.99.1:8050/public/breeds?petType=Dog,gateWay 服务会选择正确的映射,但它会以不正确的方式构建 url:

gateWay 服务构建 http://7a32a826ec7a:8070/public/breeds?petType=Dog 而不是 http://7a32a826ec7a:8070/v1/public/breeds?petType=Dog(使用 v1 在网址中)

我不明白为什么。你能帮帮我吗?

【问题讨论】:

  • 你的重写路径表达式需要一个斜杠
  • 感谢您的回答@spencergibb!应该怎么做?
  • 为什么网关在第一次调用中构建 url ok?
  • 第一个调用有斜线

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


【解决方案1】:

我修复了它,更改了 RewritePath:

RewritePath=/public/breeds/(?/?.), /v1/public/breeds/${segment}
RewritePath=/(?/?.
), /v1/${segment}

【讨论】:

    猜你喜欢
    • 2021-07-23
    • 2021-10-21
    • 2021-05-24
    • 1970-01-01
    • 2013-09-11
    • 2020-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多