web-dev-qa-db-ja.com

Java 13を使用してSpring-Bootアプリケーションを設定する方法

私はopenJdk12で正常に実行および実行されるSpring-Bootアプリケーションを作成しています。アプリケーション: https://github.com/jactor-rises/jactor-persistence

OpenJdk13で設定する方法を探しています。

スプリングブートで試してみました2.1.8.RELEASEおよび2.1.9.RELEASEですが、どちらのバージョンもIllegalStateExceptionでランタイムに失敗します。

Java.lang.IllegalStateException: Failed to load ApplicationContext

    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.Java:125)
    at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.Java:108)
    at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.Java:190)
    at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.Java:132)
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.Java:246)
    at org.springframework.test.context.junit.jupiter.SpringExtension.postProcessTestInstance(SpringExtension.Java:97)
    at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$invokeTestInstancePostProcessors$5(ClassTestDescriptor.Java:349)
    at org.junit.jupiter.engine.descriptor.JupiterTestDescriptor.executeAndMaskThrowable(JupiterTestDescriptor.Java:215)
    at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$invokeTestInstancePostProcessors$6(ClassTestDescriptor.Java:349)
    at Java.base/Java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.Java:195)
    at Java.base/Java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.Java:177)
    at Java.base/Java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.Java:1621)
    at Java.base/Java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.Java:484)
    at Java.base/Java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.Java:474)
    at Java.base/Java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining(StreamSpliterators.Java:312)
    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:658)
    at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.invokeTestInstancePostProcessors(ClassTestDescriptor.Java:348)
    at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.instantiateAndPostProcessTestInstance(ClassTestDescriptor.Java:270)
    at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$testInstanceProvider$2(ClassTestDescriptor.Java:259)
    at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$testInstanceProvider$3(ClassTestDescriptor.Java:263)
    at Java.base/Java.util.Optional.orElseGet(Optional.Java:362)
    at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$testInstanceProvider$4(ClassTestDescriptor.Java:262)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.Java:82)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.Java:59)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$prepare$0(NodeTestTask.Java:83)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.Java:72)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.prepare(NodeTestTask.Java:83)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.Java:69)
    at Java.base/Java.util.ArrayList.forEach(ArrayList.Java:1507)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.Java:38)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$4(NodeTestTask.Java:112)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.Java:72)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.Java:98)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.Java:74)
    at Java.base/Java.util.ArrayList.forEach(ArrayList.Java:1507)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.Java:38)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$4(NodeTestTask.Java:112)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.Java:72)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.Java:98)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.Java:74)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.Java:32)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.Java:57)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.Java:51)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.Java:220)
    at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.Java:188)
    at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.Java:202)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.Java:181)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.Java:128)
    at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.Java:69)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.Java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.Java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.Java:70)
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [/Users/jactor/ws/jactor-persistence/target/test-classes/com/github/jactor/persistence/DtoMapperTest.class]; nested exception is org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet: file [/Users/jactor/ws/jactor-persistence/target/test-classes/com/github/jactor/persistence/DtoMapperTest.class]; nested exception is Java.lang.IllegalArgumentException: Unsupported class file major version 57
    at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.scanCandidateComponents(ClassPathScanningCandidateComponentProvider.Java:454)
    at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.Java:316)
    at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.Java:275)
    at org.springframework.context.annotation.ComponentScanAnnotationParser.parse(ComponentScanAnnotationParser.Java:132)
    at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.Java:287)
    at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.Java:242)
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.Java:199)
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.Java:167)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.Java:315)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.Java:232)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.Java:275)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.Java:95)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.Java:705)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.Java:531)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.Java:744)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.Java:391)
    at org.springframework.boot.SpringApplication.run(SpringApplication.Java:312)
    at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.Java:120)
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.Java:99)
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.Java:117)
    ... 53 more
Caused by: org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet: file [/Users/jactor/ws/jactor-persistence/target/test-classes/com/github/jactor/persistence/DtoMapperTest.class]; nested exception is Java.lang.IllegalArgumentException: Unsupported class file major version 57
    at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.Java:57)
    at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.Java:103)
    at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.Java:123)
    at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.scanCandidateComponents(ClassPathScanningCandidateComponentProvider.Java:430)
    ... 72 more
Caused by: Java.lang.IllegalArgumentException: Unsupported class file major version 57
    at org.springframework.asm.ClassReader.<init>(ClassReader.Java:184)
    at org.springframework.asm.ClassReader.<init>(ClassReader.Java:166)
    at org.springframework.asm.ClassReader.<init>(ClassReader.Java:152)
    at org.springframework.asm.ClassReader.<init>(ClassReader.Java:273)
    at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.Java:54)
    ... 75 more
7
jactor-rises

前述のように ここ で、プロジェクトをSpringブートバージョン2.2.0に移行できます。
また、 pgrade ビルドツール(ここではGradleを使用しています)も必要です。
サンプルプロジェクト: Github

  1. Gradleを6.0-rc-1に取得/更新します。gradleをアップグレードするまで、Java-8/11をポイントするようにしてください(つまり、Java_HOMEがJava-8/11に設定されています)。
    ./gradlew wrapper --gradle-version=6.0-rc-1 --distribution-type=all
    Java-13を使用するGradleには bugbug-1 が知られていますが、6.0-rc-1バージョンで修正されています。

  2. ここ からOpenJDK-13を取得し、Java_HOMEをJava-13に設定します

  3. コメント更新ASMでも@ dirk-deyneが言及しているように、 Ref
  4. プロジェクトを構築する

追伸 https://start.spring.io/ を使用する場合は、必ずJava version 13.を選択してください。 enter image description here

0
dkb