1

I started my project with this sample https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-data-ldap.

But when I add the dependency spring-boot-starter-data-rest I have PersistentEntity must not be null!error even if I add spring.data.rest.detectionStrategy=annotated in application.properties (How to disable the default exposure of Spring Data REST repositories? and https://github.com/spring-projects/spring-ldap/issues/373). I have the same error if i try this @RepositoryRestResource(exported = false) on the PersonRepository.

Is it a bug or am I missing something?

Thanks

Person.java :

package sample.data.ldap;

import javax.naming.Name;

import org.springframework.ldap.odm.annotations.Attribute;
import org.springframework.ldap.odm.annotations.Entry;
import org.springframework.ldap.odm.annotations.Id;

@Entry(objectClasses = { "person", "top" })
public class Person {

@Id
private Name dn;

@Attribute(name = "telephoneNumber")
private String phone;

@Override
public String toString() {
    return String.format("Customer[dn=%s, phone='%s']", this.dn,  this.phone);
 }
}

PersonRepository.java :

package sample.data.ldap;

import org.springframework.data.ldap.repository.LdapRepository;

public interface PersonRepository extends LdapRepository<Person> {

Person findByPhone(String phone);

}

error :

Caused by: java.lang.IllegalArgumentException: PersistentEntity must not be null!
at org.springframework.util.Assert.notNull(Assert.java:134)
at   org.springframework.data.rest.core.mapping.RepositoryAwareResourceMetadata.<init>(RepositoryAwareResourceMetadata.java:52)
at org.springframework.data.rest.core.mapping.RepositoryResourceMappings.populateCache(RepositoryResourceMappings.java:90)
at org.springframework.data.rest.core.mapping.RepositoryResourceMappings.<init>(RepositoryResourceMappings.java:76)
at org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration.resourceMappings(RepositoryRestMvcConfiguration.java:619)
at org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration$$EnhancerBySpringCGLIB$$5f6eca9d.CGLIB$resourceMappings$12(<generated>)
at org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration$$EnhancerBySpringCGLIB$$5f6eca9d$$FastClassBySpringCGLIB$$aab3a667.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358)
at org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration$$EnhancerBySpringCGLIB$$5f6eca9d.resourceMappings(<generated>)
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:498)
at   org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
... 39 more

pom.xml :

    <dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-ldap</artifactId>
    </dependency>

    <dependency>
        <groupId>com.unboundid</groupId>
        <artifactId>unboundid-ldapsdk</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>
    </dependencies>
Keldran
  • 11
  • 3
  • No one is going to search the whole linked github project, you should just add the code snippet at what you are getting the exception. – Mehraj Malik Dec 25 '17 at 14:04

2 Answers2

1

I have run into this issue as well, and it currently affects both the 1.5.x release and 2.0.0.x milestone versions of Spring Boot. I tried with both Java and Kotlin (1.2.10 and 1.2.21), and with the Spring-Data-Rest dependency confined to a child module project.

Unfortunately, it looks like Spring-Data-REST tries to scan everything that extends/implements the base Spring-Data repository interfaces, even if they are annotated with @RepositoryRestResource(exported = false) with the detection strategy set to annotated. Interfaces that extend LdapRepository and are scoped as package-protected (Java), internal (Kotlin), or private static under another class are still picked up by Spring-Data-Rest and still cause the resource mapping error.

Sorry for the bad news, but it looks like the two cannot coexist in the same project.

This may be a regression of Spring-LDAP #373 / LDAP-341.

Edit: It is worth pointing out that Spring's LDAP Template functionality is not affected, so you can have Spring-Data-LDAP as a dependency in your project; you just can't use the LDAP repository API.

N. DaSilva
  • 174
  • 3
  • 4
0

I don't think this (LDAP @Entry's) is working with Spring Data REST (yet).

It "currently supports JPA, MongoDB, Neo4j, Solr, Cassandra, Gemfire ". No mention of LDAP.

DerM
  • 1,497
  • 1
  • 14
  • 27
  • That's why I use spring.data.rest.detectionStrategy=annotated to ignore this repository. I want to use Spring Data Rest for another repository and not for PersonRepository. – Keldran Dec 25 '17 at 15:14
  • That was not clear. Can you post the rest of your code? Is the other Entity/Repository properly defined? – DerM Dec 25 '17 at 16:05
  • I just did a simple example to prove my issue. Data Rest does not ignore this repository in spite of the @RepositoryRestResource(exported = false) or spring.data.rest.detectionStrategy=annotated. My question is how can I work with Spring Data Rest and spring LDAP in the same project? – Keldran Dec 25 '17 at 16:42
  • 2
    True until Spring Data LDAP 2.0.2. Spring Data REST support is available from version 2.0.3 (see https://jira.spring.io/browse/DATALDAP-60). You need to register a custom converter between `Name` and `String` to use entities with a `@Id Name`. – mp911de Mar 08 '18 at 11:53
  • @mp911de can you tell me what kind of converter do you mean? and how to use it? I'm having the same problem and I'm getting this stack trace: https://pastecode.xyz/view/2e562ac8 I'm using latest spring-data-ldap:2.1.9.RELEASE version – GiorgiSh Jun 20 '19 at 14:39