1 Reply Latest reply on Nov 26, 2019 7:36 AM by emiliocuberos

    Wildfly can't find persistence units to inject into CDI managed bean

    emiliocuberos

      I have an app working well in Java 8 and Wildfly 10. The driver for the Postgres database is the PostgreSQL JDBC Driver 42.2.8

       

      But after updating to Java 11 and Wildfly 17, the different persistence units from the persistence.xml are no longer found. The message is:

       

           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 demo-app.war for injection point private javax.persistence.EntityManager ProgramRepository.em

       

      Here is the definition of one the persistence-units at persistence.xml:

       

          <persistence-unit name="my-persistence-unit" transaction-type="JTA">

              <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

              <jta-data-source>java:/jboss/datasources/my_datasource</jta-data-source>

              <class>com.demo-app.cloud.entity.config.CopyTextConfig</class>

              <class>com.demo-app.cloud.entity.config.SystemConfig</class>

              <exclude-unlisted-classes>true</exclude-unlisted-classes>

              <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>

              <properties>

                  <property name="javax.persistence.schema-generation.database.action" value="none"/>

              </properties>

          </persistence-unit>

       

      This is a class where a persistence-unit is injected, using the PersistenceContext annotation. The class 'Program' maps a table in the database with help of the annotation @Entity and @Table:

       

          @Dependent

          public class ProgramRepository extends AbstractRepository<Program> {

         

              @PersistenceContext(unitName = "my-persistence-unit")

              private EntityManager em;

         

              @Override

              EntityManager entityManager() {

                  return em;

              }

       

      Here is the datasource from Wildfly's standalone.xml

       

              <datasources>

                  <datasource jndi-name="java:jboss/datasources/my_datasource" pool-name="my_datasource">

                      <connection-url>jdbc:postgresql://localhost:5432/my_database</connection-url>

                      <driver-class>org.postgresql.Driver</driver-class>

                      <driver>postgresql-42.2.8.jar</driver>

                      <security>

                          <user-name>xxxx</user-name>

                          <password>xxxx</password>

                      </security>

                      <validation>

                          <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker"/>

                          <background-validation>true</background-validation>

                          <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter"/>

                      </validation>

                  </datasource>

                  <drivers>

                      <driver name="h2" module="com.h2database.h2">

                          <xa-datasource-class&gt;org.h2.jdbcx.JdbcDataSource</xa-datasource-class&gt;

                      </driver>

                  </drivers>

              </datasources>

       

      The stack-trace complains about the 'ApiResource' class, which looks like this:

       

          @Path("birds")

          public class ApiResource {

         

              @GET

              public Response check() {

                  return Response.ok().build();

              }

          }

       

      See @ApplicationPath here:

       

          @ApplicationPath("api")

          public class ApplicationConfig extends Application {

         

              @Override

              public Set<Class<?>> getClasses() {

                  final Set<Class<?>> classes = new HashSet<>();

                  classes.add(ApiResource.class);

                  return classes;

              }

          }

       

       

      Finally, the full stack-trace from Wildfly:

       

          11:18:42,181 WARN  [org.jboss.as.jaxrs] (management-handler-thread - 1) WFLYRS0017: Failed to read attribute from JAX-RS deployment at [

              ("deployment" => "demo-app.war"),

              ("subsystem" => "jaxrs"),

              ("rest-resource" => "com.demo-app.cloud.api.system.ApiResource")

          ] with name "sub-resource-locators": java.lang.NullPointerException

              at org.wildfly.extension.undertow@17.0.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentService.getDeployment(UndertowDeploymentService.java:166)

              at org.jboss.as.jaxrs@17.0.1.Final//org.jboss.as.jaxrs.DeploymentRestResourcesDefintion$AbstractRestResReadHandler.execute(DeploymentRestResourcesDefintion.java:216)

              at org.jboss.as.controller@9.0.2.Final//org.jboss.as.controller.operations.global.ReadAttributeHandler.doExecuteInternal(ReadAttributeHandler.java:174)

              at org.jboss.threads@2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)

              at java.base/java.lang.Thread.run(Thread.java:834)

              at org.jboss.threads@2.3.3.Final//org.jboss.threads.JBossThread.run(JBossThread.java:485)

         

          11:18:42,408 ERROR [org.jboss.as.controller.management-operation] (management-handler-thread - 1) WFLYCTL0013: Operation ("read-attribute") failed - address: ([

              ("deployment" => "demo-app.war"),

              ("subsystem" => "jaxrs"),

              ("rest-resource" => "com.demo-app.cloud.api.system.ApiResource")

          ]): java.lang.IllegalArgumentException: value is null

              at org.jboss.dmr@1.5.0.Final//org.jboss.dmr.ModelNode.<init>(ModelNode.java:185)

              at org.jboss.as.controller@9.0.2.Final//org.jboss.as.controller.AbstractOperationContext.addResponseWarning(AbstractOperationContext.java:377)

              at org.jboss.as.jaxrs@17.0.1.Final//org.jboss.as.jaxrs.DeploymentRestResourcesDefintion$AbstractRestResReadHandler.execute(DeploymentRestResourcesDefintion.java:320)

              at org.jboss.as.controller@9.0.2.Final//org.jboss.as.controller.operations.global.ReadAttributeHandler.doExecuteInternal(ReadAttributeHandler.java:174)

              at org.jboss.as.controller@9.0.2.Final//org.jboss.as.controller.operations.global.ReadAttributeHandler.doExecute(ReadAttributeHandler.java:136)

          org.jboss.threads@2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486) at org.jboss.threads@2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377) at java.base/java.lang.Thread.run(Thread.java:834) at org.jboss.threads@2.3.3.Final//org.jboss.threads.JBossThread.run(JBossThread.java:485)

         

          INFO messages here

         

          11:18:50,355 INFO  [org.jboss.weld.Event] (MSC service thread 1-6) WELD-000411: Observer method [BackedAnnotatedMethod] public org.omnifaces.VetoAnnotatedTypeExtension.processAnnotatedType(@Observes ProcessAnnotatedType<T>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.

          11:18:50,368 WARN  [org.jboss.weld.Bootstrap] (MSC service thread 1-6) WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class com.sun.faces.flow.FlowDiscoveryCDIHelper is deprecated from CDI 1.1!

          11:18:50,375 INFO  [io.smallrye.metrics] (MSC service thread 1-6) MicroProfile: Metrics activated (SmallRye Metrics version: 2.3.0)

          11:18:50,442 INFO  [org.jboss.weld.Bootstrap] (Weld Thread Pool -- 2) WELD-001125: Illegal bean type org.infinispan.cdi.embedded.event.AbstractEventBridge<org.infinispan.notifications.cachelistener.event.Event<?, ?>> ignored on [EnhancedAnnotatedTypeImpl] public @Dependent class org.infinispan.cdi.embedded.event.cache.CacheEventBridge

          11:18:50,453 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-6) MSC000001: Failed to start service jboss.deployment.unit."demo-app.war".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."demo-app.war".WeldStartService: Failed to start service

              at org.jboss.msc@1.4.8.Final//org.jboss.msc.service.ServiceControllerImpl$StartTask.execute(ServiceControllerImpl.java:1729)

              at org.jboss.msc@1.4.8.Final//org.jboss.msc.service.ServiceControllerImpl$ControllerTask.run(ServiceControllerImpl.java:1557)

              at org.jboss.threads@2.3.3.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)

              at org.jboss.threads@2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1982)

              at org.jboss.threads@2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)

              at org.jboss.threads@2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)

              at java.base/java.lang.Thread.run(Thread.java:834)

          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 demo-app.war for injection point private javax.persistence.EntityManager com.demo-app.cloud.repository.ProgramRepository.em

              at org.jboss.as.weld.jpa@17.0.1.Final//org.jboss.as.weld.services.bootstrap.WeldJpaInjectionServices.getScopedPUName(WeldJpaInjectionServices.java:105)

              at org.jboss.as.weld.jpa@17.0.1.Final//org.jboss.as.weld.services.bootstrap.WeldJpaInjectionServices.registerPersistenceContextInjectionPoint(WeldJpaInjectionServices.java:68)

              at org.jboss.weld.core@3.1.1.Final//org.jboss.weld.injection.ResourceInjectionFactory$PersistenceContextResourceInjectionProcessor.getResourceReferenceFactory(ResourceInjectionFactory.java:174)

         

              at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)

              at java.base/java.lang.Thread.run(Thread.java:834)

              at org.jboss.threads@2.3.3.Final//org.jboss.threads.JBossThread.run(JBossThread.java:485)

         

          11:18:50,462 ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 2) WFLYCTL0013: Operation ("full-replace-deployment") failed - address: ([]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"demo-app.war\".WeldStartService" => "Failed to start service

              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 demo-app.war for injection point private javax.persistence.EntityManager com.demo-app.cloud.repository.ProgramRepository.em"}}

          11:18:50,485 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) WFLYSRV0016: Replaced deployment "demo-app.war" with deployment "demo-app.war"

          11:18:50,486 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 2) WFLYCTL0183: Service status report

          WFLYCTL0186:   Services which failed to start:      service jboss.deployment.unit."demo-app.war".WeldStartService: Failed to start service

         

          11:42:11,276 WARN  [org.jboss.as.jaxrs] (management-handler-thread - 3) WFLYRS0017: Failed to read attribute from JAX-RS deployment at [

              ("deployment" => "demo-app.war"),

              ("subsystem" => "jaxrs"),

              ("rest-resource" => "com.demo-app.cloud.api.system.ApiResource")

          ] with name "sub-resource-locators": java.lang.NullPointerException

              at org.wildfly.extension.undertow@17.0.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentService.getDeployment(UndertowDeploymentService.java:166)

              at org.jboss.as.jaxrs@17.0.1.Final//org.jboss.as.jaxrs.DeploymentRestResourcesDefintion$AbstractRestResReadHandler.execute(DeploymentRestResourcesDefintion.java:216)

              at org.jboss.as.controller@9.0.2.Final//org.jboss.as.controller.operations.global.ReadAttributeHandler.doExecuteInternal(ReadAttributeHandler.java:174)

              at org.jboss.threads@2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)

              at java.base/java.lang.Thread.run(Thread.java:834)

              at org.jboss.threads@2.3.3.Final//org.jboss.threads.JBossThread.run(JBossThread.java:485)

         

          11:42:11,363 ERROR [org.jboss.as.controller.management-operation] (management-handler-thread - 3) WFLYCTL0013: Operation ("read-attribute") failed - address: ([

              ("deployment" => "demo-app.war"),

              ("subsystem" => "jaxrs"),

              ("rest-resource" => "com.demo-app.cloud.api.system.ApiResource")

          ]): java.lang.IllegalArgumentException: value is null

              at org.jboss.dmr@1.5.0.Final//org.jboss.dmr.ModelNode.<init>(ModelNode.java:185)

              at org.jboss.as.controller@9.0.2.Final//org.jboss.as.controller.AbstractOperationContext.addResponseWarning(AbstractOperationContext.java:377)

              at org.jboss.as.jaxrs@17.0.1.Final//org.jboss.as.jaxrs.DeploymentRestResourcesDefintion$AbstractRestResReadHandler.execute(DeploymentRestResourcesDefintion.java:320)

              at org.jboss.as.controller@9.0.2.Final//org.jboss.as.controller.operations.global.ReadAttributeHandler.doExecuteInternal(ReadAttributeHandler.java:174)

              at org.jboss.threads@2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)

              at java.base/java.lang.Thread.run(Thread.java:834)

              at org.jboss.threads@2.3.3.Final//org.jboss.threads.JBossThread.run(JBossThread.java:485)

         

         

          INFO messages here

         

          11:42:18,541 INFO  [org.jboss.weld.Event] (MSC service thread 1-4) WELD-000411: Observer method [BackedAnnotatedMethod] public org.omnifaces.VetoAnnotatedTypeExtension.processAnnotatedType(@Observes ProcessAnnotatedType<T>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.

          11:42:18,573 WARN  [org.jboss.weld.Bootstrap] (MSC service thread 1-4) WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class com.sun.faces.flow.FlowDiscoveryCDIHelper is deprecated from CDI 1.1!

          11:42:18,579 INFO  [io.smallrye.metrics] (MSC service thread 1-4) MicroProfile: Metrics activated (SmallRye Metrics version: 2.3.0)

          11:42:18,659 INFO  [org.jboss.weld.Bootstrap] (Weld Thread Pool -- 5) WELD-001125: Illegal bean type org.infinispan.cdi.embedded.event.AbstractEventBridge<org.infinispan.notifications.cachelistener.event.Event<?, ?>> ignored on [EnhancedAnnotatedTypeImpl] public @Dependent class org.infinispan.cdi.embedded.event.cache.CacheEventBridge

          11:42:18,667 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC000001: Failed to start service jboss.deployment.unit."demo-app.war".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."demo-app.war".WeldStartService: Failed to start service

              at org.jboss.msc@1.4.8.Final//org.jboss.msc.service.ServiceControllerImpl$StartTask.execute(ServiceControllerImpl.java:1729)

              at org.jboss.msc@1.4.8.Final//org.jboss.msc.service.ServiceControllerImpl$ControllerTask.run(ServiceControllerImpl.java:1557)

              at org.jboss.threads@2.3.3.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)

              at org.jboss.threads@2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1982)

              at org.jboss.threads@2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)

              at org.jboss.threads@2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)

              at java.base/java.lang.Thread.run(Thread.java:834)

          Caused by: java.lang.IllegalArgumentException: WFLYWELD0037: Error injecting persistence unit into CDI managed bean. Can't find a persistence unit named 'userprofile-persistence-unit' in deployment demo-app.war for injection point private javax.persistence.EntityManager com.demo-app.cloud.repository.UserProfileRepository.em

              at org.jboss.as.weld.jpa@17.0.1.Final//org.jboss.as.weld.services.bootstrap.WeldJpaInjectionServices.getScopedPUName(WeldJpaInjectionServices.java:105)

              at org.jboss.as.weld.jpa@17.0.1.Final//org.jboss.as.weld.services.bootstrap.WeldJpaInjectionServices.registerPersistenceContextInjectionPoint(WeldJpaInjectionServices.java:68)

              at org.jboss.weld.core@3.1.1.Final//org.jboss.weld.injection.ResourceInjectionFactory$PersistenceContextResourceInjectionProcessor.getResourceReferenceFactory(ResourceInjectionFactory.java:174)

         

              at org.jboss.weld.core@3.1.1.Final//org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:55)

              at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)

              at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)

              at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)

              at java.base/java.lang.Thread.run(Thread.java:834)

              at org.jboss.threads@2.3.3.Final//org.jboss.threads.JBossThread.run(JBossThread.java:485)

         

          11:42:18,712 ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 2) WFLYCTL0013: Operation ("full-replace-deployment") failed - address: ([]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"demo-app.war\".WeldStartService" => "Failed to start service

              Caused by: java.lang.IllegalArgumentException: WFLYWELD0037: Error injecting persistence unit into CDI managed bean. Can't find a persistence unit named 'userprofile-persistence-unit' in deployment demo-app.war for injection point private javax.persistence.EntityManager com.demo-app.cloud.repository.UserProfileRepository.em"}}

          11:42:18,743 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) WFLYSRV0016: Replaced deployment "demo-app.war" with deployment "demo-app.war"

          11:42:18,743 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 2) WFLYCTL0183: Service status report

          WFLYCTL0186:   Services which failed to start:      service jboss.deployment.unit."demo-app.war".WeldStartService: