我使用此示例https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-data-ldap启动了我的项目。
但是当我添加依赖spring-boot-starter-data-rest时
我有
即使我在application.properties中添加PersistentEntity must not be null!
,也会出现spring.data.rest.detectionStrategy=annotated
错误
(How to disable the default exposure of Spring Data REST repositories?和https://github.com/spring-projects/spring-ldap/issues/373)。如果我在PersonRepository上尝试这个@RepositoryRestResource(exported = false)
,我会遇到同样的错误。
这是一个错误还是我错过了什么?
由于
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>
答案 0 :(得分:1)
我也遇到过这个问题,它目前影响Spring Boot的1.5.x版本和2.0.0.x里程碑版本。我尝试使用Java和Kotlin(1.2.10和1.2.21),并将Spring-Data-Rest依赖性限制在子模块项目中。
不幸的是,看起来Spring-Data-REST尝试扫描扩展/实现基本Spring-Data存储库接口的所有内容,即使它们使用@RepositoryRestResource(exported = false)注释并且检测策略设置为注释。扩展LdapRepository并且作为包受保护(Java),内部(Kotlin)或另一个类下的私有静态的接口仍然被Spring-Data-Rest接收并仍然导致资源映射错误。
对于坏消息感到抱歉,但看起来这两个人不能在同一个项目中共存。
这可能是Spring-LDAP #373 / LDAP-341的回归。
编辑:值得指出的是,Spring的LDAP模板功能不受影响,因此您可以将Spring-Data-LDAP作为项目中的依赖项;你不能使用LDAP存储库API。
答案 1 :(得分:0)
我不认为这(LDAP @Entry
)正在使用Spring Data REST。
它“currently supports JPA, MongoDB, Neo4j, Solr, Cassandra, Gemfire ”。没有提到LDAP。