在此处遵循 spring.io 示例:http://spring.io/guides/gs/accessing-data-rest/将存储库公开为休息 Web 服务工作正常,但我看不到如何更改公开服务的 URL。 API 文档对于注释参数的含义有点模糊,可能假设了一些先验知识。
我想要什么 - 访问 HATEOAS 服务 http://localhost:8080/api/people
对于人员存储库。我只想使用注释来实现这个 URL,而不是搞乱上下文根或类似的东西。我尝试了以下存储库注释:
@RepositoryRestResource(collectionResourceRel = "api/people", path = "people")
@RepositoryRestResource(collectionResourceRel = "people", path = "api/people")
@RepositoryRestResource(collectionResourceRel = "api/people", path = "api/people")
这些都不起作用。
我知道我可能错过了显而易见的事情,非常感谢任何能指出这一点的人。
最佳答案
截至 Spring Boot 1.2您可以设置此属性:spring.data.rest.baseUri=api
或者:spring.data.rest.base-uri=api
(Spring Boot 使用 relaxed binding 系统)
注意:我发现如果您扩展了 RepositoryRestMvcConfiguration
自定义配置,属性不生效。有关更多信息,请参阅:
https://github.com/spring-projects/spring-boot/issues/2392
一旦发布下一版本的 Spring Boot(1.2.1 之后),解决方案将是扩展 RepositoryRestMvcBootConfiguration
反而。
关于rest - Spring Boot Starter Data Rest 从根 URI 更改存储库的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23377036/