728x90
Error
Description:
Parameter 1 of constructor in com.projectname.api.loan.request.LoanRequestServiceImpl required a bean of type 'com.projectname.domain.repository.UserInfoRepository' that could not be found.
Action:
Consider defining a bean of type 'com.projectname.domain.repository.UserInfoRepository' in your configuration.
Error 원인
Error 내용을 확인해보면 말 그대로 스프링이 bean인식을 못하고 있기 때문에 생기는 에러이다.
에러가 발생한 클래스를 살펴보자
package com.projectname.domain.repository
... import
interface UserInfoRepository: JpaRepository<UserInfo, Long> {
fun findByUserKey(userKey: String): UserInfo
}
해당 클래스는 JpaRepository를 상속하고 있기 때문에 JpaRepository가 bean으로 인식될 수 있도록 해야한다.
해결하기
어노테이션을 설정하여 bean으로 인식이 될 수 있게 하자!
설정은 실행하는 메인클래스에 설정해도 되고, 따로 설정파일을 만들어도 된다.
여기서는 따로 설정파일을 생성하여 설정해주려고 한다.
@Configuration
@EnableJpaAuditing
@EnableJpaRepositories(basePackages = ["com.projectname.domain"])
class JpaAuditingConfiguration {
}
@Configuration으로 설정 파일임을 알려주고
아래에 JPA 관련 어노테이션으로 설정을 해준다.
이렇게 따로 설정파일을 생성하면 단위테스트를 할 때에도 편리하다.
728x90
'spring > spring' 카테고리의 다른 글
[Spring][스프링 부트 핵심 가이드] 예외처리 (0) | 2024.02.28 |
---|---|
[Spring][스프링부트핵심가이드] 유효성 검사(Validation) (0) | 2024.02.26 |
[Spring][Error] creating bean with name 'jpaAuditingHandler (0) | 2024.02.11 |
[Spring][Error][Swagger]documentationPluginsBootstrapper (0) | 2024.02.11 |
[스프링 부트 핵심 가이드] Logback 설정 (0) | 2024.02.01 |