Spring Data Rest 基本路径 [英] Spring Data Rest base path
问题描述
我通过创建扩展 RepositoryRestMvcConfiguration 的 Java 配置类并将 @RestResource 添加到存储库中,将 Spring Data Rest (2.0) 添加到现有 Spring MVC 应用程序中.
I have added Spring Data Rest (2.0) to an existing Spring MVC application by creating a Java config class that extends RepositoryRestMvcConfiguration, and adding @RestResource to the repositories.
是否可以更改 Rest API 的基本 URL?例如:
Is it possible to change the base URL for the Rest API? E.g:
http://localhost:8080/rest/customers
代替
http://localhost:8080/customers
我尝试使用 setBaseURI 覆盖 configureRepositoryRestConfiguration,但它似乎不适用于响应中的所有链接.
I tried to override configureRepositoryRestConfiguration using setBaseURI, but it didn't seem to apply to all links in the response.
推荐答案
我通过添加第二个AbstractAnnotationConfigDispatcherServletInitializer"解决了我的问题:
I solved my problem by adding a second "AbstractAnnotationConfigDispatcherServletInitializer":
public class RestWebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return null;
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class<?>[] { RepositoryRestMvcConfiguration.class };
}
@Override
protected String[] getServletMappings() {
return new String[] { "/rest/*" };
}
@Override
protected Filter[] getServletFilters() {
return null;
}
@Override
protected String getServletName() {
return "rest-exporter";
}
}
这篇关于Spring Data Rest 基本路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!