【问题标题】:spring-data-rest generating wrong entity links in proxy setupspring-data-rest 在代理设置中生成错误的实体链接
【发布时间】:2017-03-30 08:36:46
【问题描述】:

我将我的 Spring Boot 应用程序部署在 Apache 支持的反向代理后面。该代理已经正确设置了标题X-Forwarded-Proto 和X-Forwarded-Host。但是,spring-data-rest 会生成奇怪的实体和端点链接。 例如。请求news 资源:

GET https://myproxyhost.net/api/news

对此作出回应:

{
  "_embedded" : {
    "news" : [ {
      "title" : "Testnews",
      "_links" : {
        "self" : {
          "href" : "https://myproxyhost.net/api/news/api/news/1"
        },
        "news" : {
          "href" : "https://myproxyhost.net/api/news/api/news/1{?projection}",
          "templated" : true
        }
      }
    } ]
  },
  "_links" : {
    "self" : {
      "href" : "https://myproxyhost.net/api/news/api/news"
    },
    "profile" : {
      "href" : "https://myproxyhost.net/api/news/api/profile/news"
    },
    "search" : {
      "href" : "https://myproxyhost.net/api/news/api/news/search"
    }
  },
  "page" : {
    "size" : 20,
    "totalElements" : 1,
    "totalPages" : 1,
    "number" : 0
  }
}

正如您所见,链接以某种方式翻了一番,我不知道为什么。我使用的唯一 spring-data-rest 特定属性是:

spring.data.rest.base-path=/api

此外,在我的本地设置中,一切正常,所以我猜代理对此负有某种责任。

有人知道这里出了什么问题吗?提前致谢!

【问题讨论】:

    标签: spring apache spring-data-rest spring-hateoas


    【解决方案1】:

    问题是 ReverseProxy 设置的不正确配置导致 url 像

    http://proxiedhost.net:8080//api/news
    

    因此导致上述问题中提到的奇怪网址。

    【讨论】:

      猜你喜欢
      • 2015-03-14
      • 1970-01-01
      • 2015-11-29
      • 2020-07-06
      • 1970-01-01
      • 2017-06-27
      • 2018-08-22
      • 2017-10-15
      • 1970-01-01
      相关资源
      最近更新 更多