티스토리 뷰
https://spring.io/projects/spring-data-ldap#overview
Spring Data LDAP
The Spring Data LDAP project provides repository abstractions for Spring LDAP on top of Spring LDAP’s LdapTemplate and Object-Directory Mapping.
spring.io
Overview
Spring LDAP용 Spring Data는 새로운 Spring LDAP에 대해 친숙하고 일관된 Repository 추상화를 제공하는 것을 목표로 하는 umbrella Spring Data 프로젝트의 일부입니다.
Introduction
Spring Data LDAP 프로젝트는 Spring LDAP의 LdapTemplate 과 Object-Directory Mapping 위에 Spring LDAP에 대한 리포지토리 추상화를 제공합니다.
Features
- Java 기반 @Configuration 클래스 또는 XML 네임스페이스를 사용한 Spring 구성 지원.
- 주석 기반 매핑 메타데이터
- 사용자 정의 쿼리 방법에 대한 지원을 포함하여 리포지토리 인터페이스의 자동 구현.
- type-safe 쿼리를 지원하는 QueryDSL 통합
https://docs.spring.io/spring-data/ldap/docs/current/reference/html/#ldap.repositories
Spring Data LDAP - Reference Documentation
Example 10. Repository definitions using domain classes with annotations interface PersonRepository extends Repository { … } @Entity class Person { … } interface UserRepository extends Repository { … } @Document class User { … } PersonRepository re
docs.spring.io
7. LDAP Repositories
이 장에서는 LDAP에 대한 리포지토리 지원의 특수성에 대해 설명합니다. Spring 데이터 리포지토리 작업에서 설명된 핵심 리포지토리 지원을 기반으로 합니다. 당신은 저기에 설명된 기본 개념에 대해 제대로 이해해야 합니다.
Spring 데이터 리포지토리(=저장소) 작업
Spring Data 저장소 추상화의 목표는 다양한 영구 저장소의 데이터 액세스 계층을 구현하는 데 필요한 보일러 플레이트 (=상용구) 코드의 양을 크게 줄이는 것입니다.
핵심 개념
Spring Data 리포지토리 추상화에서 핵심 인터페이스는 Repository 입니다. 우리는 리포지토리를 타입인자로서 도메인 클래스의 ID타입을 사용할 뿐만 아니라 도메인 클래스를 관리하기 위해서도 사용합니다. 이 인터페이스는 주로 사용할 유형을 캡처하고 이 유형을 확장하는 인터페이스를 검색하는 데 도움이 되는 마커 인터페이스 역할을 합니다. CrudRepository 인터페이스는 관리 중인 엔티티 클래스에 대한 정교한 CRUD 기능을 제공합니다.
쿼리 메소드들
표준 CRUD 기능 저장소에는 일반적으로 기본 데이터스토어에 대한 쿼리가 있습니다. Spring Data를 사용하면 이러한 쿼리를 선언하는 4단계 프로세스가 됩니다.
1. 다음 예제처럼 Repository를 확장하는 인터페이스를 선언하고 처리해야 하는 도메인 클래스 와 ID 타입을 입력합니다.
interface PersonRepository extends Repository<Person, Long> { … }
2. 인터페이스에 쿼리 메서드를 선언합니다.
interface PersonRepository extends Repository<Person, Long> {
List<Person> findByLastname(String lastname);
}
3. JavaConfig 또는 XML 구성을 사용하여 해당 인터페이스에 대한 프록시 인스턴스를 생성하도록 Spring을 설정합니다.
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@EnableJpaRepositories
class Config { … }
4. 다음 예제와 같이 리포지토리 인스턴스를 주입하고 사용합니다.
class SomeClient {
private final PersonRepository repository;
SomeClient(PersonRepository repository) {
this.repository = repository;
}
void doSomething() {
List<Person> persons = repository.findByLastname("Matthews");
}
}
리포지토리 인터페이스 정의하기
리포지토리 인터페이스를 정의하려면 먼저 도메인 클래스별 리포지토리 인터페이스를 정의해야 합니다. 인터페이스는 Repository 를 확장해야하고 도메인 클래스 및 ID 유형을 입력해야 합니다. 해당 도메인 유형에 대한 CRUD 메서드를 표시하려면 Repository 대신 CrudRepository를 확장하십시오.
잘 튜닝된 리포지토리 정의
보통 당신의 리포지토리 인터페이스는 Repository, CrudRepository, 또는 PagingAndSortingRepository 를 확장할 것입니다. 다른 방법으로는 Spring Data 인터페이스들을 확장하지 않고 @RepositoryDefinition 어노테이션을 사용하는 방법이 있습니다. CrudRepository를 확장하면 엔티티를 조작하기 위한 완벽한 메서드 집합이 표시됩니다. 일부만 선택적으로 표시하고 싶다면 CrudRepository에서 표시하고 싶은 메서드들을 당신의 도메인 리포지토리에 복사하면 됩니다.
Spring LDAP 리포지토리로 작업할 때는 다음 사항에 유의해야 합니다.
- Spring LDAP 리포지토리는 XML 구성에서 <data-ldap:reposities> 태그를 사용하거나 구성 클래스에 대해 @EnableLdapReposities 주석을 사용하여 사용하도록 설정할 수 있습니다.
- 자동으로 생성된 리포지토리에서 LdapQuery 매개 변수에 대한 지원을 포함하기 위해서는, 당신의 인터페이스가 CrudRepository가 아닌 LdapRepository를 확장해야합니다.
- 모든 Spring LDAP 저장소는 개체-디렉토리 매핑에 설명된 대로 ODM 주석으로 주석을 단 엔티티와 함께 작동해야 합니다.
- 모든 ODM 관리 클래스는 ID로 구분된 이름을 가져야 하므로 모든 Spring LDAP 저장소는 javax.naming.Name으로 설정된 ID 유형 매개 변수를 가져야 합니다. 실제로 기본 제공 LdapRepository에서는 오직 한 유형의 매개변수만 가집니다. : javax.naming.Name 올 ID 가 기본설정 되있는 관리 엔티티 클래스.
- LDAP 프로토콜의 특수성으로 인해 Spring LDAP 저장소에 대해 페이징 및 정렬이 지원되지 않습니다.
사용법
LDAP 호환 디렉토리에 저장된 도메인 엔티티에 액세스하기 위해 구현이 상당히 쉬운 정교한 리포지토리 지원을 사용할 수 있습니다. 이렇게 하려면 다음 예제와 같이 리포지토리에 대한 인터페이스를 만듭니다.
@Entry(objectClasses = { "person", "top" }, base="ou=someOu")
public class Person {
@Id
private Name dn;
@Attribute(name="cn")
@DnAttribute(value="cn", index=1)
private String fullName;
@Attribute(name="firstName")
private String firstName;
// No @Attribute annotation means this is bound to the LDAP attribute
// with the same value
private String firstName;
@DnAttribute(value="ou", index=0)
@Transient
private String company;
@Transient
private String someUnmappedField;
// ...more attributes below
}
우리는 간단한 도메인 객체를 가지고 있습니다. 그것이 Name 타입의 dn 프로퍼티를 가지고 있는걸 주목하세요. 이 도메인 객체를 사용해서 우리는 다음과 같이 해당 유형의 개체를 보존할 저장소를 생성할 수 있습니다.
public interface PersonRepository extends CrudRepository<Person, Long> {
// additional custom finder methods go here
}
우리의 도메인 저장소는 CrudRepository를 확장하기 때문에 CRUD 작업뿐만 아니라 엔티티에 대한 액세스 방법도 제공합니다. 리포지토리 인스턴스를 클라이언트에 주입하는 작업은 종속성의 문제입니다.
'Spring' 카테고리의 다른 글
| Spring boot 에서 데이터 변경로깅 (0) | 2024.08.28 |
|---|---|
| 스프링 배치 2장 - 스프링배치 (0) | 2022.03.13 |
| 스프링배치 1장 - 배치와 스프링 (1) | 2022.03.12 |
| 스프링 배치 2 - 시작하기 (0) | 2022.03.05 |
| 스프링 배치 1 - 개요 및 아키텍처 (0) | 2022.03.05 |