【问题标题】:Simple spring-boot using gateway configured to a UI based route throws 404使用配置为基于 UI 的路由的网关的简单 spring-boot 抛出 404
【发布时间】:2019-12-13 02:48:31
【问题描述】:

我使用网关框架创建了一个简单的 spring-boot 应用程序。

路由的配置如下所示:

spring:
  cloud:
    gateway:
      routes:
      - id: rewritepath_route
        uri: http://example.org
        predicates:
        - Path=/foo/**
        filters:
        - RewritePath=/foo(?<segment>/?.*), $\{segment}

      - id: gateway_test_route
        uri: http://example.org
        predicates:
        - Path=/test

但是,前往以下任何一条路线只会显示 404:

去这个端点

显示 HTTP 错误代码 500 内部服务器错误

去执行器点:

这很好用

不确定这是否是一个问题,但路由是从网关文档中获得的。

我已经把代码上传到github.

【问题讨论】:

    标签: spring spring-boot spring-boot-actuator


    【解决方案1】:

    我不熟悉 S-C-G,但是当您通过 localhost 调用您的应用程序时,“uri”将是“localhost”而不是“example.org”。

    在本地测试此路由时,您需要使用 Postman 或 curl 等工具传递合适的 HTTP 'Host' 标头。也许还有浏览器插件。

    因此,在向本地运行的应用程序发出请求时,请尝试传递“主机:example.org”。

    【讨论】:

      猜你喜欢
      • 2020-02-05
      • 2014-06-19
      • 1970-01-01
      • 2021-02-15
      • 1970-01-01
      • 2018-05-26
      • 2022-08-10
      • 1970-01-01
      • 2018-10-04
      相关资源
      最近更新 更多