【问题标题】:spring hateoas 1.1.0 base rel path getting truncatedspring hatoas 1.1.0 基本 rel 路径被截断
【发布时间】:2020-07-27 15:54:15
【问题描述】:

我最近将我们的应用程序升级到使用 Spring Hateoas 1.1.0.RELEASE 的 Spring Boot 2.3.2.RELEASE。

我的任何链接的基本 rel 路径是:“urn:eim:linkrel:”

使用 Spring Boot 2.2.6.RELEASE,响应如下:

{
    "_links": {
        "urn:eim:linkrel:users": {
            "href": "https://localhost:8080/v1/users"
        }
    }
}

使用 Spring Boot 2.3.2.RELEASE,响应更改如下:

{
    "_links": {
        "urn:eim": {
            "href": "https://localhost:8080/v1/users"
        }
    }
}

我生成上述响应的代码:

import javax.servlet.http.HttpServletRequest;

import org.springframework.hateoas.Link;
import org.springframework.hateoas.RepresentationModel;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DemoController {

    @RequestMapping(value = "/service", method = RequestMethod.GET, produces = "application/hal+json")
    public HttpEntity<RepresentationModel<?>> service(HttpServletRequest request) {
        
        RepresentationModel<?> service = new RepresentationModel<>();

        service.add(Link.of("https://localhost:8080/v1/users", "urn:eim:linkrel:users"));

        return new ResponseEntity<>(service, HttpStatus.OK);
    }
}

有人有类似的问题吗?谁能告诉我解决此问题的解决方案。

【问题讨论】:

    标签: spring spring-boot spring-mvc spring-hateoas


    【解决方案1】:

    根据Github issue,此问题(支持多个冒号)已修复,并将在里程碑 1.2.0-M1 中发布。

    我看到修复提交在分支 1.1.x 中。我猜这个修复可能包含在修复版本 1.1.1 中。

    【讨论】:

    • 谢谢@yejianfengblue。在您提供的同一链接中找到了替代解决方案。使用这个 HalLinkRelation.uncuried(),我们可以避免这个问题,但这会在我的应用程序中添加不必要的代码。我现在会坚持使用 Spring Hateoas 1.0.5.RELEASE。当更新可用时,我将更新 1.1.1。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-09
    • 2014-03-28
    • 2011-04-01
    • 2017-01-11
    • 2018-09-20
    相关资源
    最近更新 更多