Hello Springers
Need help. My spring app runs correctly in the TDD staging environment. But when I run it inside payara application server, an error is generated:
rg.apache.catalina.LifecycleException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in br.microportador.v1.infra.spring.AppSpringConfig: Failed to instantiate [jakarta.persistence.EntityManagerFactory]: Factory method 'entityManagerFactory' threw exception with message: Provider for javax.xml.stream.XMLInputFactory cannot be found
at org.apache.catalina.core.StandardContext.start(StandardContext.java:5772)
at com.sun.enterprise.web.WebModule.start(WebModule.java:619)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:958)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:941)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:694)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1813)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1565)
at com.sun.enterprise.web.WebApplication.start(WebApplication.java:107)
at org.glassfish.internal.data.EngineRef.start(EngineRef.java:123)
at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:292)
at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:361)
at com.sun.enterprise.v3.server.ApplicationLifecycle.initialize(ApplicationLifecycle.java:630)
at fish.payara.deployment.admin.InitializeAllApplicationsCommand.execute(InitializeAllApplicationsCommand.java:75)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:556)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:552)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at java.base/javax.security.auth.Subject.doAs(Subject.java:376)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:551)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:582)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:574)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at java.base/javax.security.auth.Subject.doAs(Subject.java:376)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:573)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1497)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1869)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1755)
at com.sun.enterprise.admin.cli.embeddable.CommandExecutorImpl.executeCommand(CommandExecutorImpl.java:183)
at com.sun.enterprise.admin.cli.embeddable.CommandExecutorImpl.run(CommandExecutorImpl.java:96)
at fish.payara.micro.impl.PayaraMicroImpl.bootStrap(PayaraMicroImpl.java:1094)
at fish.payara.micro.impl.PayaraMicroImpl.create(PayaraMicroImpl.java:236)
at fish.payara.micro.impl.PayaraMicroImpl.main(PayaraMicroImpl.java:223)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at fish.payara.micro.boot.loader.MainMethodRunner.run(MainMethodRunner.java:50)
at fish.payara.micro.boot.loader.Launcher.launch(Launcher.java:114)
at fish.payara.micro.boot.loader.Launcher.launch(Launcher.java:73)
at fish.payara.micro.boot.PayaraMicroLauncher.create(PayaraMicroLauncher.java:88)
at fish.payara.micro.boot.PayaraMicroLauncher.main(PayaraMicroLauncher.java:72)
at fish.payara.micro.PayaraMicro.main(PayaraMicro.java:467)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in br.microportador.v1.infra.spring.AppSpringConfig: Failed to instantiate [jakarta.persistence.EntityManagerFactory]: Factory method 'entityManagerFactory' threw exception with message: Provider for javax.xml.stream.XMLInputFactory cannot be found
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:657)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:491)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1324)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1161)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:561)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:521)
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.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:961)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:915)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:584)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:396)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:288)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:102)
at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:5172)
at com.sun.enterprise.web.WebModule.contextListenerStart(WebModule.java:681)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:5750)
... 40 more
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [jakarta.persistence.EntityManagerFactory]: Factory method 'entityManagerFactory' threw exception with message: Provider for javax.xml.stream.XMLInputFactory cannot be found
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:171)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
... 58 more
Caused by: javax.xml.stream.FactoryConfigurationError: Provider for javax.xml.stream.XMLInputFactory cannot be found
at java.xml/javax.xml.stream.FactoryFinder.find(FactoryFinder.java:321)
at java.xml/javax.xml.stream.XMLInputFactory.newFactory(XMLInputFactory.java:288)
at com.fasterxml.jackson.dataformat.xml.XmlFactory.<init>(XmlFactory.java:115)
at com.fasterxml.jackson.dataformat.xml.XmlFactory.<init>(XmlFactory.java:101)
at com.fasterxml.jackson.dataformat.xml.XmlFactory.<init>(XmlFactory.java:85)
at com.fasterxml.jackson.dataformat.xml.XmlMapper.<init>(XmlMapper.java:127)
at org.hibernate.type.jackson.JacksonXmlFormatMapper.<init>(JacksonXmlFormatMapper.java:27)
at org.hibernate.type.jackson.JacksonIntegration.<clinit>(JacksonIntegration.java:17)
at org.hibernate.boot.internal.SessionFactoryOptionsBuilder.lambda$determineJsonFormatMapper$6(SessionFactoryOptionsBuilder.java:799)
at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveStrategy(StrategySelectorImpl.java:221)
at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveDefaultableStrategy(StrategySelectorImpl.java:181)
at org.hibernate.boot.internal.SessionFactoryOptionsBuilder.determineJsonFormatMapper(SessionFactoryOptionsBuilder.java:795)
at org.hibernate.boot.internal.SessionFactoryOptionsBuilder.<init>(SessionFactoryOptionsBuilder.java:300)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.<init>(SessionFactoryBuilderImpl.java:48)
at org.hibernate.boot.internal.DefaultSessionFactoryBuilderService.createSessionFactoryBuilder(DefaultSessionFactoryBuilderService.java:26)
at org.hibernate.boot.internal.MetadataImpl.getSessionFactoryBuilder(MetadataImpl.java:151)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1421)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:66)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:376)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:409)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:396)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:352)
at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:321)
at br.microportador.v1.infra.spring.AppSpringConfig.entityManagerFactory(AppSpringConfig.groovy:103)
at br.microportador.v1.infra.spring.AppSpringConfig$$SpringCGLIB$$0.CGLIB$entityManagerFactory$7(<generated>)
at br.microportador.v1.infra.spring.AppSpringConfig$$SpringCGLIB$$2.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:258)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
at br.microportador.v1.infra.spring.AppSpringConfig$$SpringCGLIB$$0.entityManagerFactory(<generated>)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:139)
... 59 more
]]
It seems to me that Payara's Jackson provider overlaps or conflicts with some Spring API. Any suggestions on how to resolve? Regards
Comment From: jhoeller
As far as I can see, this conflict does not seem to be with Spring API specifically but rather with Hibernate's Jackson integration which relies on the presence of a StAX provider (a javax.xml.stream.XMLInputFactory
). I'm not aware of any Payara specifics there, that StAX setup usually comes with the JDK itself.
In any case, I'd expect this to fail for any Hibernate bootstrap attempt, within or outside of Spring. You might have to tweak Hibernate's configuration to not activate its Jackson integration, or configure Payara to expose a common StAX provider.
Comment From: FernandoFranzini
When I switched from hibernate 6 to 5, it worked
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
<version>6.1.6.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core-jakarta</artifactId>
<version>5.6.14.Final</version>
</dependency>
Does this mean that there is a problem in hibernate 6x? Regards
Comment From: jhoeller
Looks like Hibernate 6 has some different Jackson integration there, so it might indeed be Hibernate 6 specific. In any case, I would expect the default Jackson integration to be configurable on Hibernate's side, turning it off completely or at least turning off the Jackson XML part of it.
Comment From: jhoeller
I'm afraid that just like #29718, this is not an actual problem to be solved on Spring's own side, as far as I can see. This needs to be taken to Hibernate and Payara. If there is anything concrete we can do from our side (based on feedback from Hibernate and/or Payara), let us know.