提问者:小点点

SpringLDAP与Spring Data Rest不兼容


我用这个样本开始了我的项目https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-data-ldap.

但是当我添加依赖spring-boot-starter-data-rest时,我有PerstientEntity不能为null!错误,即使我在application.properties中添加了spring.data.rest. detationStrategy=annotated(如何禁用Spring Data REST存储库的默认公开?和https://github.com/spring-projects/spring-ldap/issues/373)。如果我在人员存储库上尝试这个@RepositoryRestResource(导出=false),我也会遇到同样的错误。

是bug还是我错过了什么?

谢啦

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

}

错误:

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>

共2个答案

匿名用户

我也遇到了这个问题,它目前影响了Spring Boot的1.5. x版本和2.0.0.x里程碑版本。我尝试了Java和静态编程语言(1.2.10和1.2.21),并将Spring-Data-Rest依赖项限制在子模块项目中。

不幸的是,看起来Spring-Data-REST试图扫描扩展/实现基本Spring-Data存储库接口的所有内容,即使它们使用@RepositoryRestResource(导出=false)进行注释,并且检测策略设置为注释。扩展LdapRepository并范围为包保护(Java)、内部(静态编程语言)或另一个类下的私有静态的接口仍然被Spring-Data-Rest拾取,并且仍然会导致资源映射错误。

很抱歉坏消息,但看起来两者不能在同一个项目中共存。

这可能是LDAP#373/LDAP-341的回归。

编辑:值得指出的是,Spring的LDAP模板功能不受影响,因此您可以将Spring-Data-LDAP作为项目中的依赖项;您只是不能使用LDAP存储库API。

匿名用户

我不认为这(LDAP@Entry)适用于Spring Data REST(尚)。

它“目前支持JPA、MongoDB、Neo4j、Solr、Cassandra、Gemfire”。没有提到LDAP。