web-dev-qa-db-fra.com

Comment configurer une application Spring-Boot avec Java 13

Je crée une application Spring-Boot qui fonctionne et fonctionne bien avec openJdk12. L'application: https://github.com/jactor-rises/jactor-persistence

Je cherche comment le configurer avec openJdk13.

J'ai essayé avec spring-boot 2.1.8.RELEASE et 2.1.9.RELEASE, mais les deux versions échouent à l'exécution avec un 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

Comme mentionné ici , vous pouvez migrer votre projet vers Spring Boot version 2.2.0.
De plus, vous devez pgrade votre outil de build (ici j'ai utilisé Gradle).
Exemple de projet: Github

  1. Obtenir/mettre à jour gradle en 6.0-rc-1, assurez-vous de pointer vers Java-8/11 (c.-à-d. Java_HOME est défini sur Java-8/11) jusqu'à ce que vous mettiez à niveau gradle.
    ./gradlew wrapper --gradle-version=6.0-rc-1 --distribution-type=all
    Il existe bug , bug-1 pour gradle avec Java-13, qui est corrigé dans la version 6.0-rc-1.

  2. Obtenez OpenJDK-13 depuis ici , définissez Java_HOME sur Java-13

  3. Comme mentionné par @ dirk-deyne dans la mise à jour des commentaires ASM aussi, Ref
  4. Construisez votre projet

P.S. Si vous utilisez https://start.spring.io/ , assurez-vous de sélectionner Java version 13. enter image description here

0
dkb