Querydsl 강의와 연관된 질문
365
작성한 질문수 47
안녕하세요 영한님, 서포터즈님들
저는 영한님 Querydsl 강의를 다 듣고 나서 현재 강의를 듣고 있는데, 현재 강의의 querydsl 의 클래스 의존관계와 Querydsl 강의의 클래스 의존관계가 달라 궁금한 점이 생겼습니다.
기존 Querydsl 강의에서는 아래의 사진과 같은 클래스 의존관계로 만들었습니다.
public interface ItemRepositoryV3 extends JpaRepository<Item, Long>, ItemRepositoryCustom {
}
public interface ItemRepositoryCustom {
}
public class ItemRepositoryImpl implements ItemRepositoryCustom {
}
@RequiredArgsConstructor
@Service
public class ItemServiceV3 {
private final ItemRepositoryV3 itemRepositoryV3;
}
ItemServiceV3에서는 ItemRepositoryV3를 주입받는데 이때 구현체는 어떤 것인지 궁금해서 코드를 작성해보았습니다.
@SpringBootTest
class ItemServiceV3Test {
@Autowired
ItemServiceV3 itemServiceV3;
@Autowired
ItemRepositoryV3 itemRepositoryV3;
@Autowired
ItemRepositoryCustom itemRepositoryCustom;
@Test
void aa() throws Exception {
System.out.println("itemServiceV3.getClass() = " + itemServiceV3.getClass());
System.out.println("itemRepositoryV3.getClass() = " + itemRepositoryV3.getClass());
System.out.println("itemRepositoryCustom.getClass() = " + itemRepositoryCustom.getClass());
System.out.println("ProxyUtils.getUserClass(itemRepositoryV3) = " + ProxyUtils.getUserClass(itemRepositoryV3));
System.out.println("ProxyUtils.getUserClass(itemRepositoryCustom) = " + ProxyUtils.getUserClass(itemRepositoryCustom));
}
}itemServiceV3.getClass() = class hello.itemservice.repository.v3.ItemServiceV3
itemRepositoryV3.getClass() = class com.sun.proxy.$Proxy106
itemRepositoryCustom.getClass() = class com.sun.proxy.$Proxy106
ProxyUtils.getUserClass(itemRepositoryV3) = class org.springframework.data.jpa.repository.support.SimpleJpaRepository
ProxyUtils.getUserClass(itemRepositoryCustom) = class org.springframework.data.jpa.repository.support.SimpleJpaRepository
그래서 위와 같은 결과를 얻을 수 있었는데요
여기서 궁금한 점이 ItemRepositoryCustom 인터페이스는 아무런 제스처도 취하지 않았는데 왜 프록시 클래스가 만들어진건지 모르겠습니다..,,
제가 Querydsl 강의에서 놓친 부분이 있다면 어느 부분인지 말씀해주시면 감사하겠습니다.
긴 글 읽어주셔서 감사합니다.
답변 1
1
안녕하세요. gusdn85554님
ItemRepositoryCustom의 구현체 코드를 만들어두었어도 누군가는 ItemRepositoryCustom의 구현체를 호출하도록 연결을 해주어야겠지요?
ItemRepositoryCustom의 구현체를 연결하는 코드가 결국 필요한데, 스프링 데이터 JPA가 자동으로 프록시를 만들어서 해결해줍니다.
ItemRepositoryCustom의 기능을 사용하게 되면 다음과 같이 동작합니다.
클라이언트 -> Proxy -> ItemRepositoryCustom구현체
감사합니다.
0
안녕하세요 영한님
주말에도 답변 감사드립니다
생각해보니 ItemRepositoryCustomImpl를 빈으로 등록하지 않았는데 의존관계 주입이 당연히 될수가 없겠네요,, 이 부분을 간과했던 것 같습니다
그러면 결국 런타임에는 현재 ItemRepositoryCustom 에 주입된 SimpleJpaRepository가 연결해준다고 생각하면 될까요,,?
어느 부분에서 연결을 해주는지 궁금한데,, 혹시 키워드를 알 수 있을까요?
감사합니다.
0
안녕하세요. gusdn85554님
프록시 클래스가 하나 들어오는데요. 여기에서 호출해준다고 보시면 됩니다. 관련해서 따로 설명된 곳은 없어서, 디버깅을 키고 따라가보셔야 할 것 같아요^^
감사합니다.
설정 정보 없이 임베디드 데이터베이스 생성
0
41
1
RepositoryTest의 패키지 위치가 domain인 이유
0
60
2
REQUIRES_NEW 해결 방법에 대해서 질문있습니다!!
0
50
1
update()에 사용하는 setter 질문드립니다.
0
63
1
SQL 중심적 개발의 문제점에 대한 질문
0
95
1
혹시 Containing 을 안쓰신 이유가 있을까요?
0
96
2
[공유] 스프링부트 4.x 버전 mybatis 연동
0
213
1
@repository 어노테이션
0
111
3
ItemService
0
67
1
논리 커밋, 물리 커밋 질문드립니다.
0
59
1
내부 트랜잭션 커밋은 필수인가요?
0
64
1
프록시 커넥션 객체를 반환할 때 생성하는건가요?
0
63
1
Transaction readOnly 성능 개선 (김영한님의 대한 감사인사)
2
192
2
JPQL 대신 네이티브 쿼리를 사용해야 하는 경우
0
88
1
@EventListener(ApplicationReadyEvent.class) 관련
0
100
1
트랜잭션 동기화 매니저와 데이터 소스
0
83
1
DB 관련 강의 개설 계획은 없으신건가요?
0
141
2
물리 트랜잭션 과 논리트랜잭션 용어를 맞게 이해한걸까요
0
102
1
스프링 3 버전 이상 rollbackFor 변경된듯요
1
125
1
트랜잭션 전파 질문.
0
95
1
프로젝트 오픈 에러
0
138
1
외부 트랜잭션에서 isNewTransaction이 false로 나오는거에 대해 질문드립니다
0
87
2
같은 스레드를 사용하면 트랜잭션 동기화 매니저는 같은 커넥션을 반환
0
80
1
h2 인메모리 테스트중 예약어 충돌날 경우 대처방법
0
107
1





