我正在尝试通过SDR访问mongodb集合。目前使用以下版本
<spring.version>4.1.9.RELEASE</spring.version>
<spring-data-rest>2.4.4.RELEASE</spring-data-rest>
<spring-data-mongodb>1.8.4.RELEASE</spring-data-mongodb>
我的存储库看起来像
@RepositoryRestResource
@PreAuthorize("hasAuthority('ROLE_USER')")
public interface LinksRepository extends MongoRepository<Link, String> {
Page<Link> findAllByUsefulURLRegex(@Param("regex") String regex, Pageable p);
我的模型定义如下
@Document(collection = "links")
public class Link {
public Link() {}
@Id
private String id;
当我点击http://localhost:9090/api/links时,我收到以下异常
java.lang.IllegalArgumentException: PersistentEntity must not be null!
at org.springframework.util.Assert.notNull(Assert.java:112)
at org.springframework.data.rest.webmvc.PersistentEntityResource$Builder.<init>(PersistentEntityResource.java:139)
at org.springframework.data.rest.webmvc.PersistentEntityResource$Builder.<init>(PersistentEntityResource.java:122)
at org.springframework.data.rest.webmvc.PersistentEntityResource.build(PersistentEntityResource.java:114)
at org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler.wrap(PersistentEntityResourceAssembler.java:102)
at org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler.toResource(PersistentEntityResourceAssembler.java:83)
at org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler.toResource(PersistentEntityResourceAssembler.java:45)
at org.springframework.data.web.PagedResourcesAssembler.createResource(PagedResourcesAssembler.java:182)
at org.springframework.data.web.PagedResourcesAssembler.toResource(PagedResourcesAssembler.java:115)
at org.springframework.data.rest.webmvc.AbstractRepositoryRestController.entitiesToResources(AbstractRepositoryRestController.java:127)
at org.springframework.data.rest.webmvc.AbstractRepositoryRestController.toResources(AbstractRepositoryRestController.java:88)
at org.springframework.data.rest.webmvc.AbstractRepositoryRestController.toResource(AbstractRepositoryRestController.java:110)
at org.springframework.data.rest.webmvc.RepositorySearchController.executeSearch(RepositorySearchController.java:185)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:222)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:775)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:965)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:856)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
挖掘一点点我发现MongoMappingContext没有类似链接,因为它应该(我猜)
我花了几个小时试图解决它,但没有运气。我没有使用弹簧启动,它感觉它可能是一个ObjectMapper问题但我不知道,我的域和设置很简单....任何帮助非常感谢。
提前致谢。
答案 0 :(得分:3)
在不公平的投入调试这个内容之后,我设法让它在没有任何代码更改的情况下使用以下配置工作:
<spring.version>4.1.8.RELEASE</spring.version>
<spring-data-rest>2.3.2.RELEASE</spring-data-rest>
<spring-data-mongodb>1.8.0.RELEASE</spring-data-mongodb>
<spring-data-jpa>1.9.0.RELEASE</spring-data-jpa>
它可能适用于其他组合。请注意。