강의

멘토링

로드맵

인프런 커뮤니티 질문&답변

geniem님의 프로필 이미지
geniem

작성한 질문수

MemberRepositoryTest 오류

작성

·

177

0

//application.yml

//Member

//MemberRepository

//MemberRepositoryTest

 

java.lang.IllegalStateException: Failed to load ApplicationContext for [WebMergedContextConfiguration@1af1347d testClass = jpabook.jpashop.MemberRepositoryTest, locations = [], classes = [jpabook.jpashop.MemberRepository], contextInitializerClasses = [], activeProfiles = [], propertySourceDescriptors = [], propertySourceProperties = ["org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true"], contextCustomizers = [org.springframework.boot.test.autoconfigure.actuate.observability.ObservabilityContextCustomizerFactory$DisableObservabilityContextCustomizer@1f, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizer@13e39c73, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@6580cfdd, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@48ae9b55, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@72f926e6, org.springframework.boot.test.context.SpringBootTestAnnotation@7cd2ccf8], resourceBasePath = "src/main/webapp", contextLoader = org.springframework.boot.test.context.SpringBootContextLoader, parent = null]

 

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'memberRepository': Injection of persistence dependencies failed

 

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'jakarta.persistence.EntityManagerFactory' available

 

 

이런 오류가 뜨는데 뭐가 문제인지 모르겠습니다.....

답변 1

0

안녕하세요, 인프런 AI 인턴입니다.

mong_jini님, 제시한 오류 메시지를 살펴보면 java.lang.IllegalStateException이 발생하며 ApplicationContext를 로드하는 데 실패했다고 나와 있습니다. 그리고 그 원인은 BeanCreationException으로, memberRepository 빈을 생성하는 과정에서 persistence 관련 의존성 주입이 실패한 것을 알 수 있습니다. 마지막으로 NoSuchBeanDefinitionException이 발생하였으며, ‘jakarta.persistence.EntityManagerFactory’ 타입의 빈을 찾을 수 없다고 합니다.

오류 메시지에서 가장 중요한 부분은 EntityManagerFactory가 없다는 것입니다. EntityManagerFactory는 JPA를 사용할 때 필요한 핵심 컴포넌트로서, 엔티티를 관리하고 데이터베이스 작업을 위한 공장(Factory) 역할을 합니다. 이 오류는 스프링 부트 애플리케이션의 설정이나 구성에 문제가 있음을 의미합니다.

@EnableJpaRepositories@Entity 애노테이션으로 JPA 리포지토리와 엔티티를 정상적으로 사용하려면 EntityManagerFactory를 만드는 설정이 필요합니다. 예를 들어 다음과 같은 구성으로 LocalContainerEntityManagerFactoryBean을 생성해야 합니다:

@Configuration
@EnableJpaRepositories
@EnableTransactionManagement
class ApplicationConfig {

    @Bean
    public DataSource dataSource() {
        // ...
    }

    @Bean
    public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
        // ...
    }

    @Bean
    public PlatformTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
        // ...
    }
}

해결 방법으로는 다음과 같은 점을 확인해보시기 바랍니다:

  1. persistence.xml 또는 @Configuration 등을 이용한 자바 설정 파일에서 LocalContainerEntityManagerFactoryBean에 대한 빈 설정이 제대로 정의되어 있는지 확인하세요.
  2. 데이터 소스, 엔티티 관리자 팩토리(EntityManagerFactory), 트랜잭션 관리자 등 필요한 JPA 관련 빈들이 정상적으로 스프링 부트에 의해 스캔되어 등록되어 있는지 확인하세요.
  3. 사용하고 있는 테스트 클래스에 @ContextConfigurationMemberRepository만을 지정하고 있는데, JPA 설정을 포함하는 전체 애플리케이션 구성을 포함하도록 변경해야 할 수 있습니다.

위에서 언급한 ApplicationConfig 코드의 예처럼 스프링 데이터 JPA 설정이 필요합니다. 이 설정은 위에 제공된 Spring Data JPA - Reference Documentation v3.1.5 문서의 예제로 참조할 수 있으며 자세한 정보는 해당 문서 링크에서 확인하실 수 있습니다. 설정이 올바르게 되어 있는지 확인하시고, 귀하의 애플리케이션 설정을 적절히 조정해 주시기 바랍니다.

geniem님의 프로필 이미지
geniem

작성한 질문수

질문하기