인프런 커뮤니티 질문&답변

YR님의 프로필 이미지
YR

작성한 질문수

실전! 스프링 부트와 JPA 활용1 - 웹 애플리케이션 개발

JPA와 DB 설정, 동작확인

java.lang.IllegalStateException: Failed to load ApplicationContext 오류

작성

·

4.5K

0

학습하는 분들께 도움이 되고, 더 좋은 답변을 드릴 수 있도록 질문전에 다음을 꼭 확인해주세요.

[질문 내용]

MemberRepositoryTest에서 계속 오류가 발생합니다.


강사님이 진행 하시는 대로 똑같이 쳤고 강의 자료에서 하라는 것 까지 다 해보고 이것저것 몇시간을 해봤는데 계속 오류가 나요...

근데 특이한 점은 다른 분들은 처음부터 안된다고 하시는데 저는 처음에 h2 DB파일 생성한 다음 localhost모드로 바꿔서 들어가고 나서 Test를 돌리면 성공을 합니다.

실제로 테이블도 생성되구요.

근데 그 다음부터 두번째 부터는 계속 Failed to load ApplicationContext 오류가 발생합니다...

스크린샷(45).pngmember

스크린샷(46).pngmemberRepository

스크린샷(47).pngmemberRepositoryTest

스크린샷(48).pngdb 첫 생성시에는 성공 이후로 계속 오류

스크린샷(49).png스크린샷(50).pngbuild.gradle파일...

부트버전은 3.1.2구요 그래서 junit5를 사용했습니다.스크린샷(51).pngapplication.yml파일

 

 

java.lang.IllegalStateException: Failed to load ApplicationContext for [WebMergedContextConfiguration@1573e8a5 testClass = jpabook.jpashop.MemberRepositoryTest, locations = [], classes = [jpabook.jpashop.JpashopApplication], contextInitializerClasses = [], activeProfiles = [], propertySourceLocations = [], propertySourceProperties = ["org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true"], contextCustomizers = [org.springframework.boot.test.autoconfigure.actuate.observability.ObservabilityContextCustomizerFactory$DisableObservabilityContextCustomizer@1f, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@1b2abca6, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@342c38f8, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@54bff557, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@4dbb42b7, org.springframework.boot.test.context.SpringBootTestAnnotation@4ec067d1], resourceBasePath = "src/main/webapp", contextLoader = org.springframework.boot.test.context.SpringBootContextLoader, parent = null]

at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:143)

at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127)

at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:191)

at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:130)

at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:241)

at org.springframework.test.context.junit.jupiter.SpringExtension.postProcessTestInstance(SpringExtension.java:138)

at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeTestInstancePostProcessors$10(ClassBasedTestDescriptor.java:377)

at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.executeAndMaskThrowable(ClassBasedTestDescriptor.java:382)

at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeTestInstancePostProcessors$11(ClassBasedTestDescriptor.java:377)

at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)

at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)

at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)

at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)

at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)

at java.base/java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining(StreamSpliterators.java:310)

at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:735)

at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:734)

at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:762)

at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.invokeTestInstancePostProcessors(ClassBasedTestDescriptor.java:376)

at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$instantiateAndPostProcessTestInstance$6(ClassBasedTestDescriptor.java:289)

at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)

at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.instantiateAndPostProcessTestInstance(ClassBasedTestDescriptor.java:288)

at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$testInstancesProvider$4(ClassBasedTestDescriptor.java:278)

at java.base/java.util.Optional.orElseGet(Optional.java:364)

at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$testInstancesProvider$5(ClassBasedTestDescriptor.java:277)

at org.junit.jupiter.engine.execution.TestInstancesProvider.getTestInstances(TestInstancesProvider.java:31)

at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$prepare$0(TestMethodTestDescriptor.java:105)

at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)

at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:104)

at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:68)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$prepare$2(NodeTestTask.java:123)

at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.prepare(NodeTestTask.java:123)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:90)

at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)

at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)

at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)

at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)

at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)

at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)

at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)

at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)

at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)

at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)

at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)

at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:147)

at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:127)

at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:90)

at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:55)

at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:102)

at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:54)

at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)

at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)

at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)

at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53)

at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:57)

at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)

at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)

at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)

at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)

at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not instantiate id generator [entity-name=jpabook.jpashop.Member]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1770)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:598)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:520)

at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326)

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)

at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1155)

at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:608)

at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734)

at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:436)

at org.springframework.boot.SpringApplication.run(SpringApplication.java:312)

at org.springframework.boot.test.context.SpringBootContextLoader.lambda$loadContext$3(SpringBootContextLoader.java:137)

at org.springframework.util.function.ThrowingSupplier.get(ThrowingSupplier.java:58)

at org.springframework.util.function.ThrowingSupplier.get(ThrowingSupplier.java:46)

at org.springframework.boot.SpringApplication.withHook(SpringApplication.java:1406)

at org.springframework.boot.test.context.SpringBootContextLoader$ContextLoaderHook.run(SpringBootContextLoader.java:545)

at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:137)

at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:108)

at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187)

at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119)

... 72 more

Caused by: jakarta.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not instantiate id generator [entity-name=jpabook.jpashop.Member]

at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:421)

at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:396)

at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:352)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1817)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1766)

... 93 more

Caused by: org.hibernate.MappingException: Could not instantiate id generator [entity-name=jpabook.jpashop.Member]

at org.hibernate.id.factory.internal.StandardIdentifierGeneratorFactory.createIdentifierGenerator(StandardIdentifierGeneratorFactory.java:230)

at org.hibernate.id.factory.internal.IdentifierGeneratorUtil.createLegacyIdentifierGenerator(IdentifierGeneratorUtil.java:126)

at org.hibernate.mapping.SimpleValue.createGenerator(SimpleValue.java:414)

at org.hibernate.internal.SessionFactoryImpl.lambda$createGenerators$1(SessionFactoryImpl.java:413)

at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)

at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)

at java.base/java.util.HashMap$ValueSpliterator.forEachRemaining(HashMap.java:1779)

at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)

at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)

at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)

at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)

at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)

at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)

at org.hibernate.internal.SessionFactoryImpl.createGenerators(SessionFactoryImpl.java:412)

at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:249)

at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:431)

at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1455)

at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:75)

at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:376)

at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:409)

... 97 more

Caused by: org.hibernate.HibernateException: Could not fetch the SequenceInformation from the database

at org.hibernate.engine.jdbc.env.internal.ExtractedDatabaseMetaDataImpl.sequenceInformationList(ExtractedDatabaseMetaDataImpl.java:307)

at org.hibernate.engine.jdbc.env.internal.ExtractedDatabaseMetaDataImpl.getSequenceInformationList(ExtractedDatabaseMetaDataImpl.java:151)

at org.hibernate.id.enhanced.SequenceStyleGenerator.getSequenceIncrementValue(SequenceStyleGenerator.java:568)

at org.hibernate.id.enhanced.SequenceStyleGenerator.configure(SequenceStyleGenerator.java:216)

at org.hibernate.id.factory.internal.StandardIdentifierGeneratorFactory.createIdentifierGenerator(StandardIdentifierGeneratorFactory.java:224)

... 116 more

Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Column "start_value" not found [42122-214]

at org.h2.message.DbException.getJdbcSQLException(DbException.java:502)

at org.h2.message.DbException.getJdbcSQLException(DbException.java:477)

at org.h2.message.DbException.get(DbException.java:223)

at org.h2.message.DbException.get(DbException.java:199)

at org.h2.jdbc.JdbcResultSet.getColumnIndex(JdbcResultSet.java:3492)

at org.h2.jdbc.JdbcResultSet.getLong(JdbcResultSet.java:745)

at com.zaxxer.hikari.pool.HikariProxyResultSet.getLong(HikariProxyResultSet.java)

at org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorLegacyImpl.resultSetStartValueSize(SequenceInformationExtractorLegacyImpl.java:110)

at org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorLegacyImpl.lambda$extractMetadata$0(SequenceInformationExtractorLegacyImpl.java:54)

at org.hibernate.tool.schema.extract.spi.ExtractionContext.getQueryResults(ExtractionContext.java:50)

at org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorLegacyImpl.extractMetadata(SequenceInformationExtractorLegacyImpl.java:39)

at org.hibernate.engine.jdbc.env.internal.ExtractedDatabaseMetaDataImpl.sequenceInformationList(ExtractedDatabaseMetaDataImpl.java:291)

... 120 more

ㅜㅜ 진짜 3시간째 이거 잡고있는데 이유를 모르겠어요

답변 1

0

안녕하세요, 인프런 AI 인턴이에요. 에러 메시지를 보니 MemberRepositoryTest에서 ApplicationContext를 로드하는 과정에서 오류가 발생하는 것 같아요. 이 오류는 대체로 프로젝트 설정이나 의존성 문제로 발생하는 경우가 많아요.

먼저, Gradle 파일과 application.yml 파일의 설정을 확인해보세요. Gradle 파일에는 스프링 부트 버전을 지정하는 부분이 있는데, 현재 버전이 3.1.2로 되어있는 것 같아요. 스프링 부트의 최신 버전은 계속 변경되고 있으므로 버전 호환성 문제가 발생할 수 있어요. 버전을 최신 버전으로 업데이트해보고 다시 테스트해보세요.

application.yml 파일의 설정도 확인해보세요. 특히, DB 연결을 위한 설정이 있는지 확인해보세요. 그리고 DB 파일을 생성하고 접속하는 과정에서도 문제가 발생할 수 있으므로, 해당 부분에 대한 코드와 설정도 확인해보세요.

만약에 이러한 확인 작업을 했음에도 오류가 발생한다면, 다른 분들은 처음부터 안된다고 하셨지만, 저는 처음에는 성공했다고 하셨죠? 이 부분에서 차이가 있는 것 같아요. 이런 경우 다른 사람들이 작성한 게시글이나 강의 자료에 오타나 누락된 내용이 있는지, 또는 제대로 따라하고 있는지 다시 한 번 확인해보세요.

만약에 이러한 확인 작업을 했음에도 오류가 계속 발생한다면, 조금 더 자세한 정보를 제공해주시면 더 정확한 답변을 드릴 수 있을 것 같아요. 오류 메시지의 전체 내용과 함께 해당하는 코드 부분도 공유해주세요. 또한, 사용하고 있는 개발 환경에 대한 정보도 알려주시면 도움이 될 거예요.

YR님의 프로필 이미지
YR
질문자

감사합니다!! 다시 처음부터 확인해 보겠습니다!

YR님의 프로필 이미지
YR
질문자

해결했습니다!!~

h2를 삭제하고 다시 설치하니까 정상 작동하네요ㅜㅜ

버전 호환 문제였던 것 같아요.

근데 업데이트가 되면 기존에 버전은 당연히 쓰게 해줬으면 좋겠는데....

다른 분들도 많이 이런 문제를 겪고 있으신 거 같은데 그냥 데이터베이스 지웠다가 다시 설치하는게 제일 빠른 방법같네요 버전이 안맞아서 안되는 거라면.. 방법이 없으니....

 

아무튼 해결해서 너무 기분 좋습니다 ㅎㅎ

감사합니다~

YR님의 프로필 이미지
YR

작성한 질문수

질문하기