org.springframework.beans.factory.UnsatisfiedDependencyException:

pickylemon·2024년 5월 29일

Exception 모음

목록 보기
23/31

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'boardService' defined in file [...: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ... available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

상황

  • BoardService에서 BoardRepository 주입을 받지 못하는 상황.
  • MyBatis를 사용하기 때문에, Repository 인터페이스의 경로를 namespace로 가지는 SQL xml파일을 통해 Repository 구현체가 만들어져서 Service에 Autowired되어야 하는 상황인데 ApplicationContext에 Bean이 적절하게 등록되지 못하는 상황

원인 및 해결

  • Mapper를 Scan하지 못해서 발생한 결과
  • BoardRepository는 다른 Repository와 달리 한 패키지 아래에 위치해있었기 때문에, 기존에 Mapper Scan 설정으로 등록해둔 경로
    <property name="basePackage" value="com.portfolio.www.*.repository" />로는 스캔할 수가 없었다.
  • com.portfolio.www.*.repositorycom.portfolio.www.**.repository와 같이 더 아래 계층에서도 repository를 찾을 수 있도록 루트를 변경함으로써 해결함
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> 
	<property name="basePackage" value="com.portfolio.www.**.repository" />
</bean>
	
profile
안녕하세요

0개의 댓글