본문 바로가기
Error

JPA metamodel must not be empty!

by YoonJong 2022. 11. 18.
728x90

에러내용

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaAuditingHandler': Cannot resolve reference to bean 'jpaMappingContext' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: JPA metamodel must not be empty!

 

에러원인

 

@SpringbootApplication 에서 설정한 @EnableJpaAuditing 이 원인이였다.

애플리케이션 실행 시 항상 로드되는데, 모든 테스트들이 JAP 관련 Bean 을 필요로 하고 있었다.

@WebMvcTest 와 같은 슬라이스 테스트는 JPA 관련 Bean 을 로드하지 않기 때문에 에러가 발생했다.

 

 

에러조치

@MockBean(JpaMetamodelMappingContext.class)

추가해주어 해결했다.

@WebMvcTest(ReviewController.class)
@MockBean(JpaMetamodelMappingContext.class)
class ReviewControllerTest extends ControllerTest {
728x90

댓글