[Spring/스프링] required a bean of type

sbj·2024년 1월 12일
0

ERROR.zip

목록 보기
18/19

문제


원인

ReplyService 생성에 필요한 Bean을 주입 받아야 하나, ReplyService가 Bean으로 등록되어 있지 않아 발생하는 오류다.

@Autowired 어노테이션을 사용해주었으나 에러가 발생하는데, 왜?


해결법

  1. @Service, @Component 어노테이션 사용
// 보드 서비스 인터페이스
public interface BoardService {
    // 메서드 선언
}

// 보드 서비스 구현 클래스
@Service  // 또는 @Component
public class BoardServiceImpl implements BoardService {
    // 구현 내용
}

@Service, @Component 어노테이션을 사용하여 스프링 빈으로 등록할 수 있도록 한다. @Service 어노테이션은 내부적으로 @Component 어노테이션을 포함하고 있음에 유의하자.

profile
Strong men believe in cause and effect.

0개의 댓글