问题描述
我似乎不能映射我的存储库在任何位置,除了以下:
@RepositoryRestResource(collectionResourceRel = item,path =item)
public interface ItemRepository extends PagingAndSortingRepository< Item,Long> {
我以为我可以使用:
path =/ some / other / path / item
但映射不解析。我得到:
HTTP错误404
访问/ some / other / path /原因:
未找到
在spring数据中javadoc path
定义为:
您需要扩展 RepositoryRestMvcConfiguration
并重写 configureRepositoryRestConfiguration(RepositoryRestConfiguration config)
以设置您的 baseUri
。例如
@Configuration
public class MyRepositoryRestMvcConfiguration extends RepositoryRestMvcConfiguration {
private static final String MY_BASE_URI_URI =/ my / base / uri;
@Override
protected void configureRepositoryRestConfiguration(RepositoryRestConfiguration config){
super.configureRepositoryRestConfiguration(config);
config.setBaseUri(URI.create(MY_BASE_URI_URI));
}
}
I cannot seem to be able to map my Repository in any location other than the following:
@RepositoryRestResource(collectionResourceRel = "item", path = "item")
public interface ItemRepository extends PagingAndSortingRepository<Item, Long> {
I thought I can use:
path = "/some/other/path/item"
but the mapping does not resolve. I get:
HTTP ERROR 404
Problem accessing /some/other/path/item. Reason:
Not Found
In spring-data javadoc path
is defined as: "The path segment under which this resource is to be exported."
What am I doing wrong?
You need to extend the RepositoryRestMvcConfiguration
and override the configureRepositoryRestConfiguration(RepositoryRestConfiguration config)
to set yours baseUri
. e.g.
@Configuration
public class MyRepositoryRestMvcConfiguration extends RepositoryRestMvcConfiguration {
private static final String MY_BASE_URI_URI = "/my/base/uri";
@Override
protected void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
super.configureRepositoryRestConfiguration(config);
config.setBaseUri(URI.create(MY_BASE_URI_URI));
}
}
这篇关于如何将Spring Boot @RepositoryRestResource映射到特定的URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!