For the latest stable version, please use Spring Data LDAP 3.4.0! |
CDI Integration
Instances of the repository interfaces are usually created by a container, for which Spring is the most natural choice when working with Spring Data.
Spring Data LDAP includes a custom CDI extension that lets you use the repository abstraction in CDI environments.
The extension is part of the JAR.
To activate it, drop the Spring Data LDAP JAR into your classpath.
You can now set up the infrastructure by implementing a CDI Producer for the LdapTemplate
, as the following example shows:
class LdapTemplateProducer {
@Produces
@ApplicationScoped
public LdapOperations createLdapTemplate() {
ContextSource contextSource = …
return new LdapTemplate(contextSource);
}
}
The Spring Data LDAP CDI extension picks up the LdapTemplate
as a CDI bean and creates a proxy for a Spring Data repository whenever a bean of a repository type is requested by the container.
Thus, obtaining an instance of a Spring Data repository is a matter of declaring an injected property, as the following example shows:
class RepositoryClient {
@Inject
PersonRepository repository;
public void businessMethod() {
List<Person> people = repository.findAll();
}
}