Explicit bean archive with persistence.xml causes StartException (WFLYWELD0037)
mkrijgsman Sep 17, 2015 4:53 AMWhen I try to deploy a JAR with a dependency to an explicit bean archive with persistence.xml, deployment in Wildfly fails with the following stacktrace:
10:33:17,910 INFO [org.jboss.as.jpa] (ServerService Thread Pool -- 58) WFLYJPA0010: Starting Persistence Unit (phase 2 of 2) Service 'wildfly-poc-service.jar#my-persistence-unit' 10:33:17,989 INFO [org.hibernate.annotations.common.Version] (ServerService Thread Pool -- 58) HCANN000001: Hibernate Commons Annotations {4.0.5.Final} 10:33:18,118 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-3) MSC000001: Failed to start service jboss.deployment.unit."wildfly-poc-ejb.jar".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."wildfly-poc-ejb.jar".WeldStartService: Failed to start service at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1904) 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) Caused by: java.lang.IllegalArgumentException: WFLYWELD0037: Error injecting persistence unit into CDI managed bean. Can't find a persistence unit named 'my-persistence-unit' in deployment wildfly-poc-ejb.jar for injection point private javax.persistence.EntityManager org.wildfly.poc.service.MyDao.entityManager at org.jboss.as.weld.services.bootstrap.WeldJpaInjectionServices.getScopedPUName(WeldJpaInjectionServices.java:111) at org.jboss.as.weld.services.bootstrap.WeldJpaInjectionServices.registerPersistenceContextInjectionPoint(WeldJpaInjectionServices.java:74) at org.jboss.weld.injection.ResourceInjectionFactory$PersistenceContextResourceInjectionProcessor.getResourceReferenceFactory(ResourceInjectionFactory.java:351) at org.jboss.weld.injection.ResourceInjectionFactory$PersistenceContextResourceInjectionProcessor.getResourceReferenceFactory(ResourceInjectionFactory.java:339) at org.jboss.weld.injection.ResourceInjectionFactory$ResourceInjectionProcessor.createFieldResourceInjection(ResourceInjectionFactory.java:217) at org.jboss.weld.injection.ResourceInjectionFactory$ResourceInjectionProcessor.createResourceInjections(ResourceInjectionFactory.java:189) at org.jboss.weld.injection.ResourceInjectionFactory.discoverType(ResourceInjectionFactory.java:449) at org.jboss.weld.injection.ResourceInjectionFactory.getResourceInjections(ResourceInjectionFactory.java:97) at org.jboss.weld.injection.producer.ResourceInjector.<init>(ResourceInjector.java:59) at org.jboss.weld.injection.producer.ResourceInjector.of(ResourceInjector.java:49) at org.jboss.weld.injection.producer.BeanInjectionTarget.<init>(BeanInjectionTarget.java:62) at org.jboss.weld.injection.producer.BeanInjectionTarget.createDefault(BeanInjectionTarget.java:46) at org.jboss.weld.manager.InjectionTargetFactoryImpl.chooseInjectionTarget(InjectionTargetFactoryImpl.java:128) at org.jboss.weld.manager.InjectionTargetFactoryImpl.createInjectionTarget(InjectionTargetFactoryImpl.java:87) at org.jboss.weld.bean.ManagedBean.<init>(ManagedBean.java:100) at org.jboss.weld.bean.ManagedBean.of(ManagedBean.java:80) at org.jboss.weld.bootstrap.AbstractBeanDeployer.createManagedBean(AbstractBeanDeployer.java:264) at org.jboss.weld.bootstrap.BeanDeployer.createClassBean(BeanDeployer.java:228) at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$2.doWork(ConcurrentBeanDeployer.java:78) at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$2.doWork(ConcurrentBeanDeployer.java:75) at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:60) at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:53) at java.util.concurrent.FutureTask.run(FutureTask.java:266) ... 3 more
When I try to deploy the same JAR with a dependency to an implicit bean archive with persistence.xml, deployment in Wildfly succeeds without problems. Why is this the case? The CDI reference suggests that there should be no functional differences between an implicit or explicit bean archive. Copying the persistence.xml to the other artifact resolves this problem, but this is more of a workaround. I would expect that both described situations work without issues.
I have created a minimal Github repository wildfly-poc demonstrating the issue. The first case is demonstrated in branch explicit-bean-archive, the second case is demonstrated in branch implicit-bean-archive. To reproduce, the artifacts resulting from building this project can be deployed in Wildfly 9.0.1.Final, no settings need to be modified. The persistence.xml makes use of the example datasource defined out of the box in the standalone.xml.