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

mun9659님의 프로필 이미지

작성한 질문수

스프링 핵심 원리 - 기본편

옵션 처리

UnsatisfiedDependencyException 관한 질문

해결된 질문

작성

·

1.2K

0

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

[질문 내용]

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'memberServiceImpl' defined in file [F:\study\spring-boot-study2\core\out\production\classes\springbootstudy2\core\member\MemberServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0: No qualifying bean of type 'springbootstudy2.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:1356)

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

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

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

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:973)

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

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

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

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

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

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:1442)

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 'springbootstudy2.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:1418)

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

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

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

... 41 more

 

현재 [옵션 처리] 수업까지 들으면서 'CoreApplicationTests'에서 에러가 발생하고 있습니다.

 

커뮤니티 및 인터넷에서 해당 문제에 대해서 파악을 하는데... MemberRepository와 DiscountPolicy의 스프링 빈 등록이 중복되어 나온다고 설정이 되어 있는 것 같습니다

 

그래서 MemoryMemberRepository 파일과 RateDiscountPolicy 파일에 @Primary 애노테이션을 넣어서 당장 정상적으로 돌아가는 것을 확인 후 문제는 없앴지만 근본적인 문제 해결로는 이해가 되지 않아서 도움을 요청하고자 글 남겼습니다.

답변 1

4

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

혹시 스프링 부트 3.2버전으로 프로젝트를 생성하셨다면,

자주하는 질문을 참고해주십쇼! 🙂

https://docs.google.com/document/d/1j0jcJ9EoXMGzwAA2H0b9TOvRtpwlxI5Dtn3sRtuXQas/edit#heading=h.b1yk4ued1pxo

감사합니다.

mun9659님의 프로필 이미지
mun9659
질문자

감사합니다

mun9659님의 프로필 이미지

작성한 질문수

질문하기