We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bean 네이밍은 크게 두 가지가 있다.
자동 네이밍
@Component // 자동으로 "naming"으로 빈 네임이 설정된다 (lowerCamelCase) public class Naming { }
수동 네이밍
@Component("naming") public class NoName { }
스프링 부트 환경인 곳과 아닌 곳에서 위 네이밍이 충돌하는 경우에 어떻게 쓰이는지 살펴보자.
정상실행되지만 Overriding 되는 것을 볼 수 있다
01:04:19.317 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Overriding bean definition for bean 'memoryMemberRepository' with a different definition: replacing [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; initMethodName=null; destroyMethodName=null; ... 생략
런타임시에 에러가 발생하고 아예 종료된다
Action: Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
위 메세지를 보면 default option으로 오버라이딩이 false인 것을 알 수 있고, 오버라이딩 기능을 원하는 경우 옵션을 변경할 수 있다.
수동 네이밍과 자동 네이밍이 충돌하는 경우는 절대 의도한 경우는 아닐 것이고 개발자의 실수인 경우가 대부분일 것이라 예상된다. 즉, 오버라이딩된 경우도 의도한 경우가 아닌데 실행에는 문제가 없다는 것은 큰 문제를 야기할 수 있다.
The text was updated successfully, but these errors were encountered:
feat(test): 빈 네이밍 충돌 테스트 코드 추가
c4b8ef2
REF: #4
No branches or pull requests
What
Bean 네이밍은 크게 두 가지가 있다.
스프링 부트 환경인 곳과 아닌 곳에서 위 네이밍이 충돌하는 경우에 어떻게 쓰이는지 살펴보자.
스프링 부트가 아닌 환경
스프링 부트
위 메세지를 보면 default option으로 오버라이딩이 false인 것을 알 수 있고, 오버라이딩 기능을 원하는 경우 옵션을 변경할 수 있다.
결론
수동 네이밍과 자동 네이밍이 충돌하는 경우는 절대 의도한 경우는 아닐 것이고 개발자의 실수인 경우가 대부분일 것이라 예상된다.
즉, 오버라이딩된 경우도 의도한 경우가 아닌데 실행에는 문제가 없다는 것은 큰 문제를 야기할 수 있다.
The text was updated successfully, but these errors were encountered: