강의

멘토링

커뮤니티

인프런 커뮤니티 질문&답변

여섯포반장님의 프로필 이미지
여섯포반장

작성한 질문수

스프링 데이터 JPA

상속 없는 Custom Repository Interface가 어떻게 동작이 가능 한 건가요??

작성

·

334

0

안녕하세요 

'스프링 DATA Common2- Interface 정의' 강좌가 이해가 안됩니다

강의내용 예제 처럼 CustomRepository를 만들었고 save() 와 findAll() 메소드에는 구현체가 없는데 어떻게 data가 

저장이 되고 찾아 지는건가요?

이전 강좌에서 만는 Repository interface는  JpaRepository 를 extend 받았고, 그 위로 어찌어찌 찾아가다 보니 구현 체인 SimpleJpaRepository 란 놈에서 save()가 구현 되는걸 알았습니다.

근데 아래의 제가 만든 CommentRepsoity 는 상속 받은 interface가 하나도 없는데 됩니다.

Interface 위에 붙은 Annotation (@RepositoryDefinition) 때문에 알아서 내부적으로 save(), findAll() 를 

구현 해주는건가요???

package com.example.SpringDataJPATest.repository;

import com.example.SpringDataJPATest.domain.Comment;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.RepositoryDefinition;

import java.io.Serializable;
import java.util.List;

@RepositoryDefinition(domainClass = Comment.class, idClass = Long.class)
public interface CommentRepository {

Comment save(Comment comment);
List<Comment> findAll();
}

답변 1

1

백기선님의 프로필 이미지
백기선
지식공유자

네 추측하신대로 @RepositoryDefinition 애노테이션을 가지고 있는 코드를 찾아서 기본 저장소로 인터페이스로 사용하기 때문이죠.

여섯포반장님의 프로필 이미지
여섯포반장

작성한 질문수

질문하기