Je viens de migrer vers JDK 11 afin d’utiliser la dernière version Java LTS. Si je change le JRE d’exécution dans Eclipse de 10 à 11 (et alors seulement), lorsque j’essaie d’exécuter mon tests, j'obtiens l'exception stacktrace suivante (j'ai supprimé certaines parties pour faciliter la lecture).
Veuillez noter que tout fonctionne comme prévu si je reviens à jdk-10. Évidemment, j'utilise Spring boot et Hibernate comme mon ORM. J'ai déjà vérifié l'article dans http://in.relation.to/2018/09/13/using-hibernate-orm-with-jdk11/ et essayé de résoudre ce problème de dépendances. Mon pom.xml est également affiché ici.
Existe-t-il une incompatibilité connue entre Spring Boot et/ou Hibernate avec jdk-11? Peut-être une autre référence manquante dans pom.xml?
Edit: Comme indiqué correctement par @nullpointer, Spring 5.1 prend en charge Java 11. Cependant, ma question fait explicitement référence à Spring Boot.
pom.xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.0.1</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.Apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>3.5.4</version>
</dependency>
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
<skipTests>true</skipTests>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>
Trace de la pile:
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.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.Java:227)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.Java:289)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.Java:12)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.Java:291)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.Java:246)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.Java:97)
at org.junit.runners.ParentRunner$3.run(ParentRunner.Java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.Java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.Java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.Java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.Java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.Java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.Java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.Java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.Java:190)
at org.junit.runners.Suite.runChild(Suite.Java:128)
at org.junit.runners.Suite.runChild(Suite.Java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.Java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.Java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.Java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.Java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.Java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.Java:363)
at org.Eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.Java:86)
at org.Eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.Java:38)
at org.Eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.Java:538)
at org.Eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.Java:760)
at org.Eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.Java:460)
at org.Eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.Java:206)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in gr.certh.inab.ddiws.Application: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.Java:1699)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.Java:573)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:495)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.Java:317)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.Java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:315)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:199)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.Java:1089)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.Java:859)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.Java:550)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.Java:762)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.Java:398)
at org.springframework.boot.SpringApplication.run(SpringApplication.Java:330)
at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.Java:139)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.Java:99)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.Java:117)
... 33 more
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.Java:402)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.Java:377)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.Java:341)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.Java:1758)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.Java:1695)
... 48 more
Caused by: org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.Java:123)
at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.Java:77)
at org.hibernate.metamodel.internal.MetamodelImpl.initialize(MetamodelImpl.Java:129)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.Java:300)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.Java:462)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.Java:892)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.Java:57)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.Java:365)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.Java:390)
... 52 more
Caused by: org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.Tuple.entity.PojoEntityTuplizer]
at org.hibernate.Tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.Java:91)
at org.hibernate.Tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.Java:116)
at org.hibernate.Tuple.entity.EntityMetamodel.<init>(EntityMetamodel.Java:382)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.Java:519)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.Java:124)
at Java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at Java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.Java:62)
at Java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.Java:45)
at Java.base/Java.lang.reflect.Constructor.newInstance(Constructor.Java:490)
at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.Java:96)
... 60 more
Caused by: Java.lang.reflect.InvocationTargetException
at Java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at Java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.Java:62)
at Java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.Java:45)
at Java.base/Java.lang.reflect.Constructor.newInstance(Constructor.Java:490)
at org.hibernate.Tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.Java:88)
... 69 more
Caused by: Java.lang.NullPointerException
at javassist.util.proxy.SecurityActions.setAccessible(SecurityActions.Java:103)
at javassist.util.proxy.DefineClassHelper.toClass3(DefineClassHelper.Java:151)
at javassist.util.proxy.DefineClassHelper.toClass2(DefineClassHelper.Java:134)
at javassist.util.proxy.DefineClassHelper.toClass(DefineClassHelper.Java:95)
at javassist.util.proxy.FactoryHelper.toClass(FactoryHelper.Java:131)
at javassist.util.proxy.ProxyFactory.createClass3(ProxyFactory.Java:530)
at javassist.util.proxy.ProxyFactory.createClass2(ProxyFactory.Java:515)
at javassist.util.proxy.ProxyFactory.createClass1(ProxyFactory.Java:451)
at javassist.util.proxy.ProxyFactory.createClass(ProxyFactory.Java:422)
at org.hibernate.proxy.pojo.javassist.JavassistProxyFactory.postInstantiate(JavassistProxyFactory.Java:75)
at org.hibernate.Tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.Java:162)
at org.hibernate.Tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.Java:156)
at org.hibernate.Tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.Java:58)
... 74 more
Je suppose que le problème est qu'Hibernate dépend d'une ancienne version de Javassist. Vous devez utiliser 3.23.1-GA :
<dependency>
<!-- update Hibernate dependency on Javassist
to 3.23.1 for Java 11 compatibility -->
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.23.1-GA</version>
</dependency>