본문 바로가기

Dev. Debug/프로그램

[Spring & mybatis] org.springframework.beans.factory.NoSuchBeanDefinitionException

에러


org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'replyController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.zerock.service.ReplyService org.zerock.controller.ReplyController.service; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.zerock.service.ReplyService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.inject.Inject()}


에러 분석

파란 글씨를 보면 Bean 생성시 예외가 발생한다고 함.

ReplyController에서 ReplyService 객체를 사용하고 있는데 ReplyService  bean 객체를 찾지 못해서 나오는 에러


해결

클래스 객체를 new방식이 아닌 DI 방식으로 사용하기 위해서는 클래스를 객체로 등록 해줘야 한다.

그래서 소스를 다시 살펴보니

ReplyService 를 구현한 클래스에 어노테이션 정의(@Service)를 안 적어 줬던 것!!!

난 객체로 등록되지도 않은 걸 컨트롤러에서 썻으니 에러가 나는게 당현했던거다 ㅡㅡㅋ