Spring data rest mongodb java.lang.IllegalArgumentException: PersistentEntity must not be null

I am trying to access the mongodb collection via SDR. Working with future versions currently

<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> 

My repository looks like

 @RepositoryRestResource @PreAuthorize("hasAuthority('ROLE_USER')") public interface LinksRepository extends MongoRepository<Link, String> { Page<Link> findAllByUsefulURLRegex(@Param("regex") String regex, Pageable p); 

My model is defined as follows

 @Document(collection = "links") public class Link { public Link() {} @Id private String id; 

When I clicked http: // localhost: 9090 / api / links , I get the following exception

 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) 

Digging a bit, I found that MongoMappingContext does not have a Link class, as it should (I think)

enter image description here

I spent several hours trying to figure it out, but no luck. I do not use spring boot and it feels that this may be an ObjectMapper problem, but I don’t know, my domain and setup are simple ... any help is much appreciated.

Thanks in advance.

+5
source share
1 answer

After an unfair time spent debugging this courage, I managed to get it to work without changing the code on my side with the following configuration:

  <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> 

It may work with a different combination. Just beware.

+3
source

All Articles