rest - Spring Boot Starter Data Rest 从根 URI 更改存储库的 URL

标签 rest spring-boot

在此处遵循 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/

    相关文章:

    Spring Data REST - 发布具有关系的新实体

    java - 无法使用网关 UI 将数据保存到 JHipster 微服务中

    Spring-boot @EnableJpaRepositories 仅在满足 @Conditional 时

    java - SolrHealthIndicator 不带已弃用的 CompositeHealthIndicator

    java - 值在 java spring Controller 中使用 post 方法接收 null

    JavaScript REST 客户端库

    泰国 REST API 直销信用卡

    ios - 轨道 API : Authenticate users from native mobile apps using username/password or facebook token

    ios - 使用 REST 使捆绑 Realm 保持最新

    spring-boot - Spring Cloud配置服务器git连接问题