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

이성원님의 프로필 이미지

작성한 질문수

스프링 핵심 원리 - 기본편

조회 빈이 2개 이상 - 문제

CoreApplication 오류

24.01.04 23:12 작성

·

451

0

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

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

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

[질문 내용]
test 전체 실행을 하였더니
java.lang.IllegalStateException: Failed to load ApplicationContext for [MergedContextConfiguration@4c777e7b testClass = hello.core.CoreApplicationTests, locations = [], classes = [hello.core.CoreApplication], 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@5a4ed68f, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@3956b302, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@100f9bbe, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@1a78dacd, org.springframework.boot.test.context.SpringBootTestAnnotation@85e8c2c7], 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.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:141)

at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:97)

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

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

at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)

at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)

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

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.StreamSpliterators$WrappingSpliterator.forEachRemaining(StreamSpliterators.java:310)

at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:735)

at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:734)

at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:762)

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

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

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

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'memberServiceImpl' defined in file [C:\Users\YWJEONG\study\core\out\production\classes\hello\core\member\MemberServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0: No qualifying bean of type 'hello.core.member.MemberRepository' available: expected single matching bean but found 2: memoryMemberRepository,memberRepository

at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:802)

at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:241)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1354)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1191)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:561)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:521)

at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:325)

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:323)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:975)

at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:960)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:625)

at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762)

at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:464)

at org.springframework.boot.SpringApplication.run(SpringApplication.java:334)

at org.springframework.boot.test.context.SpringBootContextLoader.lambda$loadContext$3(SpringBootContextLoader.java:137)

at org.springframework.util.function.ThrowingSupplier.get(ThrowingSupplier.java:58)

at org.springframework.util.function.ThrowingSupplier.get(ThrowingSupplier.java:46)

at org.springframework.boot.SpringApplication.withHook(SpringApplication.java:1458)

at org.springframework.boot.test.context.SpringBootContextLoader$ContextLoaderHook.run(SpringBootContextLoader.java:552)

at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:137)

at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:108)

at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:225)

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

... 17 more

Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'hello.core.member.MemberRepository' available: expected single matching bean but found 2: memoryMemberRepository,memberRepository

at org.springframework.beans.factory.config.DependencyDescriptor.resolveNotUnique(DependencyDescriptor.java:218)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1420)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1353)

at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:911)

at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:789)

... 41 more

이런 오류가 뜹니다 ㅠㅠ

답변 2

1

OMG님의 프로필 이미지

2024. 01. 05. 00:25

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

AI 답변 링크 중 첫번째 답변을 참고해주세요 🙂

감사합니다.

1

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

2024. 01. 04. 23:16

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

질문하신 내용은 스프링 컨테이너에서 특정 타입의 빈을 주입하려 할 때, 예상했던 하나의 빈 대신에 2개의 빈(memoryMemberRepository, memberRepository)이 발견되어 발생하는 NoUniqueBeanDefinitionException과 관련이 있습니다. 이에 대한 유사한 질문과 답변이 이미 있으니 아래 링크를 참고하시면 도움이 될 것 같습니다.

또한, 강의 내용과 관련된 다른 질문 게시물도 참고하실 수 있습니다.

해당 링크에서 제공되는 정보와 답변 내용을 확인하시면 문제를 해결하는 데 도움이 될 것입니다.