spring-data-rest override @RequestMapping

时间:2014-11-11 18:51:53

标签: spring-boot spring-data-rest

使用 spring-boot spring-data-rest 创建快速入门网络应用模板。

我希望允许根/进入src/resources/public/index.html文件,以便我可以启动前端,但使用 spring-data-rest {{{ 1}}映射到org.springframework.data.rest.webmvc.RepositoryController

如何将其映射移至/?我可以找到如何修改/rest的BaseUrl而不是如何释放RestRepositories

2 个答案:

答案 0 :(得分:0)

为什么要尝试直接在与前端应用程序相同的路径上运行API?

这应该在2个单独的应用程序中完成。 Spring Data + Rest应该用于创建API,而不是使用您的前端(可能在其他地方的简单apache上运行)来调用您作为后端开发人员创建的RESTful API。

在这里,您可以找到我对RESTFul API的答案: Where to put forms / alternative views in a RESTful html app?

如您所见,API正在服务器的另一台服务器/部分上运行。

答案 1 :(得分:0)

配置基础浴很简单。扩展RepositoryRestMvcConfiguration(在主Application类或单独的配置类中),然后覆盖其主配置例程,如下所示:

  @Override
  protected void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
    super.configureRepositoryRestConfiguration(config);
    try {
        config.setBaseUri(new URI("/rest"));
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
  }