본문 바로가기

WEB/Spring

[Spring] Field dao in (...) required a bean of type (...) that could not be found. 에러

현재 팀원들과 미니프로젝트를 진행중입니다. 프로젝트는 다음과 같이 진행중입니다.

  • Java 17
  • Spring Boot 3.2.0
  • Gradle

저와 같이 백엔드를 맡고 있는 팀원이 깃 커밋 후 에러가 생긴다고 연락을 해왔습니다.

문제
*************************** APPLICATION FAILED TO START ***************************

Description:

Field dao in com.ssaca.model.service.BoardServiceImpl required a bean of type 'com.ssaca.model.dao.BoardDao' that could not be found.

The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)

Action: Consider defining a bean of type 'com.ssaca.model.dao.BoardDao' in your configuration.

 

읽어보면 Bean을 찾을 수 없다는 이야기 입니다.

BoardServiceImpl로 가봤습니다. 어노테이션이 제대로 등록되어 있습니다. 스프링 부트는 지정된 범위내에 어노테이션이 붙어있으면 자동으로 빈으로 등록해주니 이건 아닌 것 같습니다. 

 

 

문제는 DBConfig에 있었습니다.

 

 

팀원이 dao, dto, service 패키지의 상위 패키지로 model 패키지를 만들어 놓았고 MapperScan의 basePackages의 경로가 꼬여서 오류가 발생한 것 이였습니다. 

 

문제 해결
@MapperScan(basePackages = "com.ssaca.dao")
-> @MapperScan(basePackages = "com.ssaca.model.dao")

 

다음과 같이 수정해주었더니 잘 작동하였습니다.