No qualifying bean of type 'com.querydsl.jpa.impl.JPAQueryFactory' available

DongHyun Kim·2023년 8월 20일
0

에러 발생 이유 ❗
JPAQuery 빈을 생성하기 위한 JPAQueryFactory 클래스를 찾지 못했다

내 코드에서 발생했던 문제
평소 @RequiredArgsConstructor 로 생성자 주입으로 받는 습관 때문에 JPAQueryFactory 도 똑같이 스프링이 주입한다 생각했다.

하지만 JPAQueryFactory 를 생성할 때 EntityManager 를 매개변수로 넘겨줘야 하므로 생성자로 EntityManager 를 주입받고 생성하도록 하자

해결 방법

@Repository
@Transactional
public class MyItemRepositoryImpl implements MyItemRepository {

    private final EntityManager em;
    private final JPAQueryFactory query;

    public MyItemRepositoryImpl(EntityManager em){
        this.em = em;
        query = new JPAQueryFactory(em);
    }
    ...
profile
do programming yourself

0개의 댓글