• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    해결됨

[JPA와 DB 설정, 동작확인] 강의에서 테스트 에러

24.04.11 21:13 작성 조회수 79

0

안녕하세요 😀 강사님께서는 <JPA와 DB 설정, 동작확인> 강의에서(12:57) 아래와 같은 에러가 나셨는데

저는 강사님과 같이 JUnit4로 같은 코드를 작성하였는데

Failed to load ApplicationContext for [WebMergedContextConfiguration@6fc1a8f6 testClass = jpabook.jpashop.MemberRepositoryTest, locations = [], classes = [jpabook.jpashop.JpashopApplication], 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@106cc338, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@26ceffa8, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@60129b9a, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@21337f7b, org.springframework.boot.test.context.SpringBootTestAnnotation@d5186646], resourceBasePath = "src/main/webapp", contextLoader = org.springframework.boot.test.context.SpringBootContextLoader, parent = null]
java.lang.IllegalStateException: Failed to load ApplicationContext for [WebMergedContextConfiguration@6fc1a8f6 testClass = jpabook.jpashop.MemberRepositoryTest, locations = [], classes = [jpabook.jpashop.JpashopApplication], 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@106cc338, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@26ceffa8, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@60129b9a, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@21337f7b, org.springframework.boot.test.context.SpringBootTestAnnotation@d5186646], resourceBasePath = "src/main/webapp", contextLoader = org.springframework.boot.test.context.SpringBootContextLoader, parent = null]

이와 같은 에러가 납니다.

이런 식으로 에러가 나는데 맞는 걸까요?

답변 2

·

답변을 작성해보세요.

0

OMG님의 프로필

OMG

2024.04.11

안녕하세요. Clain님, 공식 서포터즈 OMG입니다.

인프런 AI인턴의 답변으로 해결이 불가능한 상황일까요? 그렇다면

도움을 드리고 싶지만 질문 내용만으로는 답변을 드리기 어렵습니다.

실제 동작하는 전체 프로젝트를 압축해서 구글 드라이브로 공유해서 링크를 남겨주세요.

구글 드라이브 업로드 방법은 다음을 참고해주세요.

https://bit.ly/3fX6ygx


주의: 업로드시 링크에 있는 권한 문제 꼭 확인해주세요


추가로 다음 내용도 코멘트 부탁드립니다.

1. 문제 영역을 실행할 수 있는 방법

2. 문제가 어떻게 나타나는지에 대한 상세한 설명


링크: 공식 서포터즈

링크: 자주하는 질문

감사합니다.

Clain님의 프로필

Clain

질문자

2024.04.12

먼저 보시기 어려우셨을 텐데 죄송합니다ㅜㅜ

https://drive.google.com/file/d/1oH3J-0m4Jqgjjw-JQRwswPT2EG7uqU9d/view?usp=sharing

  1. test/MemberRepositoryTest 에서 testMember() 실행 시 에러가 납니다.

jdk, sdk 설정은 다음과 같습니다.

image

image

 

Clain님의 프로필

Clain

질문자

2024.04.12

  1. 아래와 같은 에러가 나는데 너무 길어서 댓글에 다 안적힙니다ㅜㅜ

 

Failed to load ApplicationContext for [WebMergedContextConfiguration@7cca31fc testClass = jpabook.jpashop.MemberRepositoryTest, locations = [], classes = [jpabook.jpashop.JpashopApplication], 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@1046d517, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@21337f7b, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@14fc1f0, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@3b96c42e, org.springframework.boot.test.context.SpringBootTestAnnotation@126a6750], resourceBasePath = "src/main/webapp", contextLoader = org.springframework.boot.test.context.SpringBootContextLoader, parent = null]

java.lang.IllegalStateException: Failed to load ApplicationContext for [WebMergedContextConfiguration@7cca31fc testClass = jpabook.jpashop.MemberRepositoryTest, locations = [], classes = [jpabook.jpashop.JpashopApplication], 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@1046d517, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@21337f7b, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@14fc1f0, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@3b96c42e, org.springframework.boot.test.context.SpringBootTestAnnotation@126a6750], resourceBasePath = "src/main/webapp", contextLoader = org.springframework.boot.test.context.SpringBootContextLoader, parent = null]

at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:180)

at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:130)

at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:191)

at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:130)

at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:260)

at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:228)

at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)

at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)

at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:247)

at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)

at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)

at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)

at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)

at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)

at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)

at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)

at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)

at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)

at org.junit.runners.ParentRunner.run(ParentRunner.java:413)

at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)

at org.junit.runner.JUnitCore.run(JUnitCore.java:137)

at org.junit.runner.JUnitCore.run(JUnitCore.java:115)

at org.junit.vintage.engine.execution.RunnerExecutor.execute(RunnerExecutor.java:42)

at org.junit.vintage.engine.VintageTestEngine.executeAllChildren(VintageTestEngine.java:80)

at org.junit.vintage.engine.VintageTestEngine.execute(VintageTestEngine.java:72)

at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:107)

at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)

at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)

 

Clain님의 프로필

Clain

질문자

2024.04.12

ㅜㅜㅜ헉 해결되었습니다!

단순히 h2 데이터베이스를 실행하지 않은 상태에서 테스트 케이스를 돌렸기 때문인 것 같은데 맞을까요??

David님의 프로필

David

2024.04.12

만약 h2(tcp모드)를 사용해야 하는 테스트에서 h2를 실행하지 않으신 채 테스트를 실행하셨다면 오류가 발생할 수 있습니다.

0

인프런 AI 인턴님의 프로필

인프런 AI 인턴

2024.04.11

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

Clain님께서 질문하신 내용을 보면, “[JPA와 DB 설정, 동작확인] 강의에서 테스트 에러” 관련하여 문제가 발생한 것으로 보입니다. 에러 메시지를 자세히 살펴보니, Failed to load ApplicationContextjava.lang.IllegalStateException 오류가 발생하여 스프링 애플리케이션 컨텍스트를 로드하는 데 실패한 것으로 나타나고 있습니다. 이런 유형의 오류는 스프링 부트의 설정 문제, 스프링의 의존성 주입 문제, 혹은 테스트 환경 설정이 잘못되었을 때 발생할 수 있는 상황입니다.

Clain님의 경우, 예제 코드를 따라 하셨음에도 불구하고 테스트 실행 시에 컨텍스트 로딩 실패로 이어지는 문제가 발생하였으나, 구체적인 원인 분석을 위해서는 추가적인 정보가 필요합니다.

저는 질문자님의 이해를 돕고자 지식공유자님의 기존 답변을 참고하여 유사한 답변 링크를 추천해드리고 있습니다.

특히, "안녕하세요, 인프런 AI 인턴이에요. 관련하여 JUnit 설정 혹은 스프링 부트의 테스트 관련 설정에서의 문제로 인해 발생할 수 있는 오류입니다."에서 다룬 내용이 Clain님의 질문에 부분적으로 도움이 될 수 있을지도 모르겠습니다. 해당 답변에서는 JPA와 DB 설정, 동작 확인 강의에서 테스트를 실행할 때 나타날 수 있는 문제와 그에 대한 해결 방안을 소개하고 있습니다. 특히, Hibernate와 관련된 설정, JPA의 빈 설정, 데이터베이스 연결 정보 설정 등이 문제의 원인일 수 있습니다.

스프링 부트와 JPA를 활용한 웹 애플리케이션 개발 과정에서 발생할 수 있는 다양한 설정 문제를 해결하기 위해서는 application.properties 또는 application.yml 파일의 설정을 점검해 보는 것이 중요합니다. 또한, 데이터베이스 연결, JPA 엔티티 매니저 설정 등의 다양한 구성 요소들이 정확히 설정되어 있는지 확인해야 합니다.

현재 베타 기능으로 답변이 만족스럽지 않을 수 있는 점 양해 부탁드립니다. 🙏 추가적으로 궁금한 점이 있으시면, 이어서 질문해 주세요. 곧 지식공유자께서 답변해 주실 것입니다.