mockMvc를 이용하여 회원가입 test를 하던 도중 빨간색 글씨로
java.lang.IllegalStateException: Failed to load ApplicationContext for [WebMergedContextConfiguration@5d1d9d73 testClass = piro.newcardgame.domain.user.UserControllerTest, locations = [], classes = [piro.newcardgame.NewCardGameApplication], contextInitializerClasses = [], activeProfiles = [], propertySourceLocations = [], propertySourceProperties = ["org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTestContextBootstrapper=true"], contextCustomizers = [org.springframework.boot.test.autoconfigure.OverrideAutoConfigurationContextCustomizerFactory$DisableAutoConfigurationContextCustomizer@f09733f, org.springframework.boot.test.autoconfigure.actuate.observability.ObservabilityContextCustomizerFactory$DisableObservabilityContextCustomizer@1f, org.springframework.boot.test.autoconfigure.filter.TypeExcludeFiltersContextCustomizer@f87e1fd7, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@2940130a, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizer@1750fbeb, [ImportsContextCustomizer@74ba6ff5 key = [org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration, org.springframework.boot.autoconfigure.context.MessageSourceAutoConfiguration, org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration, org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration, org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAutoConfiguration, org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration, org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration, org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration, org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration, org.springframework.boot.autoconfigure.jsonb.JsonbAutoConfiguration, org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration, org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration, org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration, org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration, org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration, org.springframework.boot.autoconfigure.web.servlet.HttpEncodingAutoConfiguration, org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcAutoConfiguration, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcWebClientAutoConfiguration, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcWebDriverAutoConfiguration, org.springframework.boot.autoconfigure.security.oauth2.client.servlet.OAuth2ClientAutoConfiguration, org.springframework.boot.autoconfigure.security.oauth2.resource.servlet.OAuth2ResourceServerAutoConfiguration, org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration, org.springframework.boot.autoconfigure.security.servlet.SecurityFilterAutoConfiguration, org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcSecurityConfiguration, org.springframework.boot.test.autoconfigure.web.reactive.WebTestClientAutoConfiguration]], org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@15a34df2, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@4722ef0c, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@cae414c5, org.springframework.boot.test.context.SpringBootTestAnnotation@b368f17e], resourceBasePath = "src/main/webapp", contextLoader = org.springframework.boot.test.context.SpringBootContextLoader, parent = null]
이런 오류가 발생하여 찾아보았더니 어디서 문제가 생겼는지 발견하려면 오류 로그를 조금 더 위로 올려서 오류를 찾아야 한다고 했다.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaAuditingHandler': Cannot resolve reference to bean 'jpaMappingContext' while setting constructor argument
그랬더니 조금 위쪽에 저런 오류가 발생한 것을 찾을 수 있었고 jpaAuditing과 관련하여 문제가 있음을 알게 되었다.
나의 경우, User entity를 만들 때 baseEntity로 createdAt, updatedAt을 Auditing 어쩌구로 자동 생성하도록 해주었는데 test에서는 이걸 불러오지 못해서 생기는 오류 같았다.
@WebMvcTest 에러 : JPA metamodel must not be empty!
1. 에러 원문 java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:132) at org.springframework.test.co
1-7171771.tistory.com
해당 글을 참고하여, test 위에
@MockBean(JpaMetamodelMappingContext.class)
어노테이션을 붙여줬더니 오류가 해결되었다.
'개발 > Springboot' 카테고리의 다른 글
[Spring] Spring boot + 구글 SMTP 서버로 이메일 보내기 (0) | 2024.01.07 |
---|---|
[Spring] Type definition error: [simple type, class ~] (0) | 2023.11.04 |
[Spring MVC] 2. JSP와 MVC 패턴 (0) | 2023.08.25 |
[Spring MVC] 1. 웹 애플리케이션의 이해와 서블릿 (HTTP 관련) (0) | 2023.08.18 |
[Spring 핵심 원리 기본편] 8. 빈 생명주기 콜백(@PostConstruct, @PreDestroy) (0) | 2023.08.16 |
댓글