채널톡 아이콘

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

오득령님의 프로필 이미지

작성한 질문수 1

스프링 입문 - 코드로 배우는 스프링 부트, 웹 MVC, DB 접근 기술

스프링 데이터 JPA

스프링 데이터 JPA 7분까지 따라 친 후 오류 메시지

작성

·

30

0

학습하는 분들께 도움이 되고, 더 좋은 답변을 드릴 수 있도록 질문전에 다음을 꼭 확인해주세요.

1. 강의 내용과 관련된 질문을 남겨주세요.
2. 인프런의 질문 게시판과 자주 하는 질문(링크)을 먼저 확인해주세요.
(자주 하는 질문 링크: https://bit.ly/3fX6ygx)
3. 질문 잘하기 메뉴얼(링크)을 먼저 읽어주세요.
(질문 잘하기 메뉴얼 링크: https://bit.ly/2UfeqCG)

질문 시에는 위 내용은 삭제하고 다음 내용을 남겨주세요.
=========================================
[질문 템플릿]
1. 강의 내용과 관련된 질문인가요? (예/아니오) 예
2. 인프런의 질문 게시판과 자주 하는 질문에 없는 내용인가요? (예/아니오) 예
3. 질문 잘하기 메뉴얼을 읽어보셨나요? (예/아니오) 예

[질문 내용]
여기에 질문 내용을 남겨주세요.

 

어떤 것이 문제인지 잘 모르겠습니다.
springConfig도 정확히 입력했고 gradle파일과 properties파일도 정확히 작성했습니다.
H2도 켜놓은 상태인데 오류가 나오네요. Member에 있는 데이터도 다 지웠고요.

 

java.lang.IllegalStateException: Failed to load ApplicationContext for [WebMergedContextConfiguration@6108fd23 testClass = hello.hello_spring.service.MemberServiceIntegrationTest, locations = [], classes = [hello.hello_spring.HelloSpringApplication], contextInitializerClasses = [], activeProfiles = [], propertySourceDescriptors = [], propertySourceProperties = ["org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true"], contextCustomizers = [org.springframework.boot.test.autoconfigure.OnFailureConditionReportContextCustomizerFactoryOnFailureConditionReportContextCustomizer@6f204a1a,org.springframework.boot.test.autoconfigure.actuate.observability.ObservabilityContextCustomizerFactoryOnFailureConditionReportContextCustomizer@6f204a1a, org.springframework.boot.test.autoconfigure.actuate.observability.ObservabilityContextCustomizerFactoryDisableObservabilityContextCustomizer@1f, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizer@7b4c50bc, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@491b9b8, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactoryDuplicateJsonObjectContextCustomizer@5a5a729f,org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0,org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@1500b2f3,org.springframework.boot.test.web.reactor.netty.DisableReactorResourceFactoryGlobalResourcesContextCustomizerFactoryDuplicateJsonObjectContextCustomizer@5a5a729f, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@1500b2f3, org.springframework.boot.test.web.reactor.netty.DisableReactorResourceFactoryGlobalResourcesContextCustomizerFactoryDisableReactorResourceFactoryGlobalResourcesContextCustomizerCustomizer@3aa078fd, org.springframework.test.context.support.DynamicPropertiesContextCustomizer@0, org.springframework.boot.test.context.SpringBootTestAnnotation@6e5c6e5c], 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:200)

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

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

at org.springframework.test.context.junit.jupiter.SpringExtension.postProcessTestInstance(SpringExtension.java:160)

at java.base/java.util.stream.ForEachOpsForEachOpForEachOpOfRef.accept(ForEachOps.java:184)

at java.base/java.util.stream.ReferencePipeline331.accept(ReferencePipeline.java:197)

at java.base/java.util.stream.ReferencePipeline221.accept(ReferencePipeline.java:179)

at java.base/java.util.stream.ReferencePipeline331.accept(ReferencePipeline.java:197)

at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1708)

at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)

at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)

at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)

at java.base/java.util.stream.ForEachOpsForEachOpForEachOpOfRef.evaluateSequential(ForEachOps.java:174)

at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)

at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)

at java.base/java.util.Optional.orElseGet(Optional.java:364)

at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)

at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'memberController' defined in file [C:\Users\deukr\hello-spring\hello-spring\out\production\classes\hello\hello_spring\controller\MemberController.class]: Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'springConfig' defined in file [C:\Users\deukr\hello-spring\hello-spring\out\production\classes\hello\hello_spring\SpringConfig.class]: Unsatisfied dependency expressed through constructor parameter 0: No qualifying bean of type 'hello.hello_spring.repository.MemberRepository' available: expected single matching bean but found 2: memoryMemberRepository,springDataJpaMemberRepository

답변 2

0

오득령님의 프로필 이미지
오득령
질문자

H2 콘솔을 초기화하고 다시 하니 해결되었네요 감사합니다 :)

0

인프런 AI 인턴님의 프로필 이미지

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

오득령님께서 경험하신 오류는 NoUniqueBeanDefinitionException으로 스프링 컨테이너가 MemberRepository 타입의 빈을 주입하려고 할 때 두 개의 빈(memoryMemberRepository, springDataJpaMemberRepository)이 발견되어 어떤 것을 선택해야 할지 모르는 상황입니다.

관련 문제를 해결할 수 있는 방법 및 이와 유사한 질문이 몇 가지 있으므로 참고하시기 바랍니다.

  1. 빈 충돌 문제 해결:

    • 스프링이 여러 빈 중 하나를 선택하도록 하기 위해 @Primary를 사용하거나, @Qualifier를 통해 명확히 주입할 빈 이름을 지정할 수 있습니다.
  2. 유사한 질문과 해결 방법:

    • 질문: CoreApplicationTests 오류
    • 관련 게시글: CoreApplicationTests 오류
    • 이 질문에서도 비슷한 빈 중복 문제가 생긴 사례를 다루고 있으니 참고하시면 도움이 될 것입니다. 이 게시글에서는 @Qualifier를 사용하거나 필요에 따라 하나의 빈을 제외하도록 설정하는 방법 등을 제시하고 있습니다.
  3. 자세한 해결책 제공:

    • 만일 두 개의 저장소(memoryMemberRepository, springDataJpaMemberRepository)를 함께 사용할 필요가 없다면, 사용하지 않는 빈을 빈 생성에서 제외하십시오.
    • @SpringBootTest의 테스트 설정에서 필요없는 빈에 대해 @MockBean을 사용할 수도 있습니다.

저는 질문자님의 이해를 돕고자 지식공유자님의 기존 답변을 참고하여 유사한 답변 링크를 추천해드리고 있습니다.
현재 베타 기능으로 답변이 만족스럽지 않을 수 있는 점 양해 부탁드립니다. 🙏
추가적으로 궁금한 점이 있으시면, 이어서 질문해 주세요. 곧 지식공유자께서 답변해 주실 것입니다.