상황
스프링 Autowired 의존성 자동주입을 사용하던 중 아래와 같이 동일한 타입의 빈이 2개 발견된다는 에러가 발생했다.
ERROR: org.springframework.test.context.TestContextManager - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@bd4dc25] to prepare test instance [com.toy.mapper.BoardServiceTests@35d3ab60]
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.toy.mapper.BoardServiceTests': Unsatisfied dependency expressed through method 'setService' parameter 0; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'com.toy.board.BoardService' available: expected single matching bean but found 2: boardServiceImpl,boardService
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:667)
해결
오류코드에 BoardService타입이 boardServiceImpl, boardService 2개 발견된다고 적혀있기때문에
"found 2: boardServiceImpl,boardService"
이 중에 하나를 필드명으로 명시한다.
//오류
@Setter(onMethod_= {@Autowired})
private BoardService service;
//해결
@Setter(onMethod_= {@Autowired})
private BoardService boardService;
'ERROR RESOLVING' 카테고리의 다른 글
오류 WebSocket connection to 'xxx' failed, Provisional headers are shown (0) | 2023.02.17 |
---|---|
오류 java.lang.IllegalArgumentException 요청 타겟에서 유효하지 않은 문자가 발견되었습니다. (0) | 2023.02.12 |
오류 Log4j - org.apache.log4j.Logger cannot be resolved to a type (0) | 2023.02.05 |
오류 class java.lang.String cannot be cast to class (0) | 2023.01.21 |
오류 Unhandled exception type IOException (0) | 2023.01.05 |