본문 바로가기
JAVA/Error

[ QueryDSL ] Parameter 0 of constructor in ArticleRepositoryCustomImpl required a bean of type 'java.lang.Class' that could not be found. 에러 해결 방법

by 알기 쉬운 코딩 사전 2024. 4. 10.
반응형

💥 Application run 시 발생한 에러 메시지

Description:
Parameter 0 of constructor in com.example.demo.repository.querydsl.ArticleRepositoryCustomImpl required a bean of type 'java.lang.Class' that could not be found.

Action:
Consider defining a bean of type 'java.lang.Class' in your configuration.

 

에러 이미지

❓에러 발생 이유

Consider defining a bean of type 'java.lang.Class' in your configuration.라는 문구는 보통 Spring이 실행되면서 java 파일이 bean 등록이 되지 않았을 때 나타나는 에러 메시지입니다.

저의 경우에는 QueryDSL을 사용한 ArticleRepositoryCustomImpl.java 파일이 spring bean에 등록이 되지 않아서 나타나는 메시지입니다.

 

✅ 해결 방법

 

✔️ 해결 방법

  • ArticleRepositoryCustomImpl의 기본 생성자를 매개변수가 없는 기본 생성자로 등록해 줍니다.
public class ArticleRepositoryCustomImpl extends QuerydslRepositorySupport implements ArticleRepositoryCustom{

// 변경 전 -> 기본 생성자
//    public ArticleRepositoryCustomImpl(Class<?> domainClass) {
//        super(Article.class);
//    }

// 변경 후 -> 매개변수가 없는 기본 생성자
    public ArticleRepositoryCustomImpl() {
        super(Article.class);
    }

    @Override
    public List<String> findAllDistinctHashtags() {
        QArticle article = QArticle.article;

        return from(article)
                .distinct()
                .select(article.hashtag)
                .where(article.hashtag.isNotNull())
                .fetch();
    }
}
반응형

댓글