【发布时间】:2019-09-10 01:16:08
【问题描述】:
当我没有为它设置控制器时,我收到了来自 localhost:8085/ponds 的响应......任何地方都没有映射。
更奇怪的是,当我访问 localhost:8085/ponds 时,我可以在应用程序中看到它正在执行一条 SQL 命令。
我在网上搜索了这个 _embedded 的来源,我发现了一些关于 HAL 和 HATEOS 的信息,但是,我没有在任何地方隐式实现这些。
我已经在终端中运行了一个 maven 全新安装和部署,我看到了这个:
INFO 16328 --- [main] osdrwRepositoryRestHandlerMapping:映射“{[/{repository}/{id}],methods=[GET],produces=[application/hal+json || application/json]}”到公共 org.springframework.http.ResponseEntity> org.springframework.data.rest.webmvc.RepositoryEntityController.getItemResource(org.springframework.data.rest.webmvc.RootResourceInformation,java.io.Serializable,org.springframework.data.rest. webmvc.PersistentEntityResourceAssembler,org.springframework.http.HttpHeaders) 抛出 org.springframework.web.HttpRequestMethodNotSupportedException
org.springframework.http.ResponseEntity
这是浏览器中的响应:
{
"_embedded" : {
"ponds" : [ ]
},
"_links" : {
"self" : {
"href" : "http://localhost:8085/ponds"
},
"profile" : {
"href" : "http://localhost:8085/profile/ponds"
}
}
}
我最后一次使用 SpringBoot 是几个月前,如果我试图访问一个我没有为其编写控制器的链接/映射/HTML 页面,我会得到一个“找不到页面”页面,而不是回应。
我正在使用 SpringBoot 2.0.5.RELEASE
我不明白为什么它会给出响应而不是错误...
所以我评论了:
<!--<dependency>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-starter-data-rest</artifactId>-->
<!--</dependency>-->
然后响应消失了。我仍然不明白为什么它使用 ResponseEntity,或者为什么 ResponseEntity 实际上返回那个 JSON...
【问题讨论】:
标签: spring-boot hateoas hal