[Spring] bean not found error

yoon·2024년 5월 7일

spring-boot

목록 보기
32/41
post-thumbnail

❌ 에러 상황

현재 프로젝트는 api와 db 두 개의 패키지를 가지고 있다.
오류는 api에서 db에 속해있는 bean을 불러올 때 발생했다

Description:
Parameter 0 of constructor in org.delivery.api.account.AccountApiController required a bean of type 'org.delivery.db.account.AccountRepository' that could not be found.
Action:
Consider defining a bean of type 'org.delivery.db.account.AccountRepository' in your configuration.

spring boot는 자신의 패키지안에서 annotation을 확인하여 baen을 등록한다.
현재 api와 db는 패키지가 다르기 때문에 bean을 확인할 수 없다는 오류가 발생한 것이다.

✅ 해결 상황

패키지 간에 bean을 확인할 수 있도록 basePakage를 설정해주자.

@Configuration
@EntityScan(basePackages = "org.delivery.db")
@EnableJpaRepositories(basePackages = "org.delivery.db")
public class JpaConfig {
}
profile
하루하루 차근차근🌱

0개의 댓글