민스씨의 일취일장
TIssue | org.springframework.beans.factory.NoSuchBeanDefinitionException 본문
TIssue | org.springframework.beans.factory.NoSuchBeanDefinitionException
읻민스 2023. 1. 17. 22:50DAO 적용 후 아래와 같은 오류가 발생
이슈 : 에러 메시지
ERROR: org.springframework.test.context.TestContextManager - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@561b6512] to prepare test instance [com.---.UserDaoImplTest@751e664e]
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.---.UserDaoImplTest': Unsatisfied dependency expressed through field 'userDao'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.---.UserDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.---.UserDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.fastcampus.ch3.UserDaoImplTest': Unsatisfied dependency expressed through field 'userDao'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.---.UserDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.---.UserDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
원인
새롭게 등록한 DAO 객체를 Bean으로 등록하지 않았기 때문에 오류가 발생했다.
해결방법
DAO 객체를 Bean으로 등록해주면 된다. DAO객체를 Interface로 변경후 Impliment, 즉 구현객체를 따로 만들었다면 Impliment 객체에 Bean 등록을 위한 Annotaion을 붙여주면 된다. 보통 Bean으로 등록하기 위해 @Component를 사용하지만 DAO 객체에는 @Repository를 사용한다.
'Programming Language & Framework > JAVA & Spring' 카테고리의 다른 글
LogT | Java Spring의 DispatcherServlet에 대해 알게된 모든 내용과 고민들 (0) | 2023.01.19 |
---|---|
LogT | Java Spring의 DAO에 대해 알게된 모든 내용과 고민들 (0) | 2023.01.17 |
LogT | Java Spring로 DB 다루기에 대해 알게된 모든 내용과 고민들 (0) | 2023.01.13 |
LogT | Java Spring의 Exception 처리에 대해 알게 된 모든 내용과 고민들 (0) | 2023.01.12 |
LogT | Java Spring의 쿠키와 세션에 대해 알게 된 모든 내용과 고민들 (0) | 2023.01.11 |