IT/Java
spring annotation-driven 시 bean name 중복(충돌,conflicts) 해결
성준하이
2022. 12. 4. 08:07
반응형
spring은 annotation-driven component scan 시 기본적으로 Bean 이름으로 id를 결정한다.(annotation으로 설정)
예를 들어 클래스명이 TestController 라면 id는 “testController” 로 결정된다.
이때 다른 패키지에서 동일한 이름을 가진 클래스(컴포넌트)가 중복으로 존재한다면 동일한 id 를 가지게 되며 아래와 같은 에러 메시지를 볼 수 있다.
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from file [.....\servlet-context.xml]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'cblController' for bean class [......CblController] conflicts with existing, non-compatible bean definition of same name and class [......CblController] |
Bean 의 이름이 겹칠때 해당 에러가 발생하니 이럴경우엔 클래스의 이름 중복이나 Bean설정 이름 부분을 확인해주면 된다.
반응형