[Spring] java.lang.IllegalStateException Create breakpoint : Failed to load ApplicationContext

김준영·2023년 10월 23일
0
post-thumbnail

[23.10.23] 게시판 만들기 프로젝트를 진행하면서 TestCase 작성하면서 발생

구글링 검색해서 에러를 해결하는게 제일 빠른 방법이라는 것을 나도 알고있다.
다만, 에러가 생겼을 때 발생한 이유와 내가 생각했던 방식 , 실제 해결방법등을 기록하기 위해서 글을 작성했다.

1. 어떻게 발생했을까 ?

  • java.lang.IllegalStateException Create breakpoint : Failed to load ApplicationContext

  • caused by: org.springframework.beans.factory.nosuchbeandefinitionexception: no qualifying bean of type 'com.querydsl.jpa.impl.jpaqueryfactory' available

2. 이 에러를 보고 나는 무슨 생각을 했을까 ?

Failed to load ApplicationContext :
Application 실행할 때 주입을 받아서 사용해야할 것에 주입을 못받았다고
생각했다.

org.springframework.beans.factory.nosuchbeandefinitionexception: no qualifying bean of type 'com.querydsl.jpa.impl.jpaqueryfactory' available :
QueryDsl을 사용하기 위해 jpaqueryfactory 를 사용했는데 bean 등록이 되지 않았다.

2-1. 그럼 뭘까 ?

즉, Bean에 JpaQueryFactory 를 등록하지 않고 주입 받는 코드를 작성했기 때문에 발생한 오류라고 할 수 있다.

3. 내가 했던 해결 방법

package mini.soccerlocation.config;

import com.querydsl.jpa.impl.JPAQueryFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@Configuration
public class QueryDslConfig {

    @PersistenceContext
    public EntityManager em;

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

}

@Configuration을 사용해서 JPAQueryFactory를 생성하는 메소드를 Bean에 등록했다.

profile
한전 퇴사 후 독일가기 위한 기록

0개의 댓글