title: JBoss EAP 7.1 Spring-Data-JPA CDI Extension
body: <p>We have an app that uses Spring Data JPA repositories to inject into EJB's.  Spring's <code>org.springframework.data.jpa.repository.cdi.JpaRepositoryExtension</code> does the magic. </p>
  
  <p>It looks for an EntityManager in CDI, saves it for later use, looks for Spring Data JPA repositories using the <code>@Repository</code> annotation, and saves their types for later use. When CDI is initialized, <code>JpaRepositoryExtension::afterBeanDiscovery</code> runs and to do the proper bean creation and insertion into CDI. This has worked perfectly under JBoss EAP 6.2/6.3/6.4.</p>
  
  <p>JBoss EAP 7.1 is built on WildFly 11 and the Hibernate version is now 5.1. The JPA bootstrap code has been restructured in JBoss and the Hibernate JPA provider. Due to this restructuring the EntityManager is <strong>not</strong> in CDI at the time that this runs:</p>
  
  <pre><code>org.springframework.data.jpa.repository.cdi.JpaRepositoryExtension.processBean(ProcessBean&lt;X&gt;)
  </code></pre>
  
  <p>This eventually causes...</p>
  
  <pre><code>org.springframework.data.jpa.repository.cdi.JpaRepositoryExtension.createRepositoryBean(Class&lt;?&gt;, Set&lt;Annotation&gt;, BeanManager)
  </code></pre>
  
  <p>...to throw:</p>
  
  <blockquote>
    <p>javax.enterprise.inject.UnsatisfiedResolutionException: Unable to
    resolve a bean for 'javax.persistence.EntityManager' with qualifiers
    [@javax.enterprise.inject.Default(), @javax.enterprise.inject.Any()].
      at
    org.springframework.data.jpa.repository.cdi.JpaRepositoryExtension.createRepositoryBean(JpaRepositoryExtension.java:120)
      at
    org.springframework.data.jpa.repository.cdi.JpaRepositoryExtension.afterBeanDiscovery(JpaRepositoryExtension.java:96)</p>
  </blockquote>
  
  <hr>
  
  <p>Has anyone successfully deployed Spring Data JPA onto JBoss EAP 7.1 or WildFly 11+ and gotten the JPA repositories created in CDI?</p>
  
  <p>Edit:
  I have a CDI Producer that works fine in EAP 6.2/3/4:</p>
  
  <pre><code>    @Produces
      @Dependent
      @PersistenceUnit( unitName="** Our PU Name **" )
      private EntityManagerFactory entityManagerFactory;
  .
  .
  .
      @Produces
      @RequestScoped
      @PersistenceContext( type = PersistenceContextType.EXTENDED )
      public EntityManager createEntityManager( EntityManagerFactory emf )
      {
          EntityManager em = emf.createEntityManager();
          return em ;
      }
  </code></pre>