인프런 커뮤니티 질문&답변
수동 빈과 자동 빈이 충돌될 때 로그에 overriding is disabled라고 남습니다.
작성
·
108
0
학습하는 분들께 도움이 되고, 더 좋은 답변을 드릴 수 있도록 질문전에 다음을 꼭 확인해주세요.
1. 강의 내용과 관련된 질문을 남겨주세요.
2. 인프런의 질문 게시판과 자주 하는 질문(링크)을 먼저 확인해주세요.
(자주 하는 질문 링크: https://bit.ly/3fX6ygx)
3. 질문 잘하기 메뉴얼(링크)을 먼저 읽어주세요.
(질문 잘하기 메뉴얼 링크: https://bit.ly/2UfeqCG)
질문 시에는 위 내용은 삭제하고 다음 내용을 남겨주세요.
=========================================
[질문 템플릿]
1. 강의 내용과 관련된 질문인가요? (예)
2. 인프런의 질문 게시판과 자주 하는 질문에 없는 내용인가요? (예)
3. 질문 잘하기 메뉴얼을 읽어보셨나요? (예)
[질문 내용]
여기에 질문 내용을 남겨주세요.
섹션 7. 컴포넌트 스캔 - 중복 등록과 충돌 강의를 실습하던 중
@Component
public class MemoryMemberRepository implements MemberRepository{}
@Configuration
@ComponentScan(
excludeFilters = @Filter(type = FilterType.ANNOTATION, classes = Configuration.class)
)
public class AutoAppConfig {
@Bean(name = "memoryMemberRepository")
public MemberRepository memberRepository(){
return new MemoryMemberRepository();
}
}
이러한 경우 자료에서는 "수동 빈 등록이 우선권을 가져서 수동빈이 자동빈을 오버라이딩 해버린다." 라고 나와 있습니다.
근데 제 콘솔 로그에는
09:37:26.010 [main] WARN o.s.c.a.AnnotationConfigApplicationContext --Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'memoryMemberRepository' defined in class path resource [hello/core/AutoAppConfig.class]: Cannot register bean definition [Root bean: class [null]; scope=; abstract=false; lazyInit=null; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=autoAppConfig; factoryMethodName=memberRepository; initMethodNames=null; destroyMethodNames=[(inferred)]; defined in class path resource [hello/core/AutoAppConfig.class]] for bean 'memoryMemberRepository' since there is already [Generic bean: class [hello.core.member.MemoryMemberRepository]; scope=singleton; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodNames=null; destroyMethodNames=null; defined in file [/Users/g.u/logInDev/T.I.L/spring/basic/codebase/core/build/classes/java/main/hello/core/member/MemoryMemberRepository.class]] bound.
(...생략....)
The bean 'memoryMemberRepository', defined in class path resource [hello/core/AutoAppConfig.class], could not be registered. A bean with that name has already been defined in file [/Users/g.u/logInDev/T.I.L/spring/basic/codebase/core/build/classes/java/main/hello/core/member/MemoryMemberRepository.class] and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true오버라이딩을 원하면 추가 옵션을 세팅하라고 나와있습니다. 이 경우에는 오버라이딩이 된게 아니고 스프링이 중단되었다고 판단됩니다.
혹시 강의에서는 추가로 옵션을 세팅한건 지 아니면 제가 잘못 코드를 작성한건 지 궁금합니다.





