TIL

플러스 주차 개인 과제 트러블 슈팅 TIL

phonebee 2025. 3. 21. 10:21

1. QueryDSL 빈 처리

● 개요

코드 테스트를 하기 위해서 실행을 시켰을 때 오류가 발생하였다.

- 오류문

Parameter 0 of constructor in org.example.expert.domain.todo.repository.TodoRepositoryImpl required a bean of type 'com.querydsl.jpa.impl.JPAQueryFactory' that could not be found.

● 원인

해당 오류문을 검색해보니

JPAQueryFactory가 빈으로 등록되지 않아 발생한 문제라고 한다.

@RequiredArgsConstructor
public class TodoRepositoryImpl implements TodoRepositoryQuery{

    private final JPAQueryFactory queryFactory;

이렇게 불러서 사용했지만 정작 빈으로 등록을 하지 않아서 생긴 문제라고 한다.

 

● 해결 과정

그래서 이를 해결하기 위해서 빈을 등록할 Config 클래스를 제작했다.

@Configuration
public class QueryDSLConfig {

    @PersistenceContext
    private EntityManager entityManager;

    @Bean
    public JPAQueryFactory jpaQueryFactory() {
        return new JPAQueryFactory(entityManager);
    }
}

먼저 @PersistenceContext를 사용하여 EntityManager를 주입받고

JPAQueryFactory를 빈으로 등록하였다.

 

그 후 다시 코드를 실행했을 때 정상적으로 작동되었음을 알 수 있었다.

'TIL' 카테고리의 다른 글

플러스 주차 개인 과제 TIL 7.  (0) 2025.03.18
플러스 주차 개인 과제 TIL 6.  (0) 2025.03.17
플러스 주차 개인 과제 TIL 5.  (0) 2025.03.14
플러스 주차 개인과제 TIL 4.  (0) 2025.03.13
플러스 주차 개인과제 TIL 3.  (0) 2025.03.12