【发布时间】:2017-10-25 01:29:39
【问题描述】:
我正在使用 Spring Boot 尝试 Spring HATEOAS。而且我放心地写了一个单元测试:
given().standaloneSetup(new GreetingApi())
.accept("application/hal+json;charset=UTF-8")
.when()
.get("/greeting")
.prettyPeek()
.then().statusCode(200)
.body("content", equalTo("Hello, World"))
.body("_links.self.href", endsWith("/greeting?name=World"));
测试返回响应如下:
Content-Type: application/hal+json;charset=UTF-8
{
"content": "Hello, World",
"links": [
{
"rel": "self",
"href": "http://localhost/greeting?name=World"
}
]
}
但实际上,当我运行整个 Spring Boot 应用程序时,响应是这样的:
HTTP/1.1 200
Content-Type: application/hal+json;charset=UTF-8
Date: Wed, 24 May 2017 15:28:39 GMT
Transfer-Encoding: chunked
{
"_links": {
"self": {
"href": "http://localhost:8080/greeting?name=World"
}
},
"content": "Hello, World"
}
所以必须有一些方法来配置HATEOAS的响应,但我没有找到。
希望熟悉这方面的人可以帮助我。
整个仓库是here。
【问题讨论】:
标签: java spring spring-mvc spring-boot spring-hateoas