自JPA 2.1起,可以将EJB注入实体侦听器。但是,WildFly 9.0.2最终失败,出现以下异常。
15:41:12,125 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 149) MSC000001: Failed to start service jboss.persistenceunit."Test.ear/Test-ejb.jar#Test-ejbPU": org.jboss.msc.service.StartException in service jboss.persistenceunit."Test.ear/Test-ejb.jar#Test-ejbPU": javax.persistence.PersistenceException: [PersistenceUnit: Test-ejbPU] Unable to build Hibernate SessionFactory
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:172)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:117)
at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:665)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:182)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
at org.jboss.threads.JBossThread.run(JBossThread.java:320)
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: Test-ejbPU] Unable to build Hibernate SessionFactory
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:877)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:805)
at org.jboss.as.jpa.hibernate5.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:154)
... 7 more
Caused by: org.jboss.weld.exceptions.IllegalArgumentException: WELD-001456: Argument resolvedBean must not be null
at org.jboss.weld.util.Preconditions.checkArgumentNotNull(Preconditions.java:40)
at org.jboss.weld.manager.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:813)
at org.jboss.weld.injection.FieldInjectionPoint.inject(FieldInjectionPoint.java:92)
at org.jboss.weld.util.Beans.injectBoundFields(Beans.java:375)
at org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:386)
at org.jboss.weld.injection.producer.ResourceInjector$1.proceed(ResourceInjector.java:70)
at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:48)
at org.jboss.weld.injection.producer.ResourceInjector.inject(ResourceInjector.java:72)
at org.jboss.weld.injection.producer.BasicInjectionTarget.inject(BasicInjectionTarget.java:121)
at org.hibernate.jpa.event.internal.jpa.BeanManagerListenerFactory$BeanMetaData.<init>(BeanManagerListenerFactory.java:65)
at org.hibernate.jpa.event.internal.jpa.BeanManagerListenerFactory$BeanMetaData.<init>(BeanManagerListenerFactory.java:54)
at org.hibernate.jpa.event.internal.jpa.BeanManagerListenerFactory.buildListener(BeanManagerListenerFactory.java:40)
at org.hibernate.jpa.event.internal.jpa.LegacyCallbackProcessor.resolveCallbacks(LegacyCallbackProcessor.java:161)
at org.hibernate.jpa.event.internal.jpa.LegacyCallbackProcessor.processCallbacksForEntity(LegacyCallbackProcessor.java:66)
at org.hibernate.jpa.event.spi.JpaIntegrator.integrate(JpaIntegrator.java:140)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:278)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:802)
... 9 more
15:41:12,125 ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 2) WFLYCTL0013: Operation ("full-replace-deployment") failed - address: ([]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.persistenceunit.\"Test.ear/Test-ejb.jar#Test-ejbPU\"" => "org.jboss.msc.service.StartException in service jboss.persistenceunit.\"Test.ear/Test-ejb.jar#Test-ejbPU\": javax.persistence.PersistenceException: [PersistenceUnit: Test-ejbPU] Unable to build Hibernate SessionFactory
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: Test-ejbPU] Unable to build Hibernate SessionFactory
Caused by: org.jboss.weld.exceptions.IllegalArgumentException: WELD-001456: Argument resolvedBean must not be null"}}
提出这个问题只是因为我读到了从WildFly 8.2开始向实体监听器注入EJB和/或CDI事件的地方。因此,我觉得我在某个地方出错了。
与GlassFish成功(至少在GlassFish 4.1上)不同,WildFly是否要求我们特别注意将EJB和/或CDI事件注入实体监听器?
我在一个完全空白的企业应用程序上对此进行了测试,该应用程序只有一个空白会话bean(无状态),它将被注入实体监听器和一些JPA实体。
听众:
public class ProductListener {
@Inject
private TestService service;
@PostPersist
public void postPersist() {
}
}
EJB完全空白:
@Stateless
public class TestBean implements TestService {
}
如果注入点(TestService
)被删除,则异常消失。
使用@ApplicationScoped
或@Singleton
指定听众也无济于事(实际上不应该这样做)。
Hibernate版本最终为5.0.5,Weld版本为2.2.16。
更新1:
更新到Hibernate 5.0.6 final。
更新2:
问题仍然存在于2016年1月29日星期五发布的 WildFly 10.0.0 final ,其中Hibernate 5.0.7 final / Weld 2.3 final。
更新3:
根据issue status,这已经在Hibernate 5.1.0 final中得到修复,它应该在WildFly 10.0.0 final中相应地工作,但它仍然无法使用相同的异常 - 没有任何改进。
答案 0 :(得分:0)
正如@Franck所指出的,它是一个错误,最终于去年仅在版本11(wildfly)中得到修复(在EAP 7.1中也得到了修复)。我们使用EAP 7.0(wildfly 10)和相同的问题,我们无法升级。解决方法是,我们现在使用@Tiny的建议,将功能移至EJB并使用@EJB
iso @Inject
。
该主题的所有用户均已获得赠金,只想将其合并到答案中以供以后参考。