민스씨의 일취일장

TIssue | org.springframework.beans.factory.NoSuchBeanDefinitionException 본문

Programming Language & Framework/JAVA & Spring

TIssue | org.springframework.beans.factory.NoSuchBeanDefinitionException

읻민스 2023. 1. 17. 22:50
반응형

DAO 적용 후 아래와 같은 오류가 발생

이슈 : 에러 메시지

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를 사용한다.

728x90
반응형