WELD-001408 Unfulfilled dependencies when entering EntityManager

I have a @Statelessbean that implements two interfaces (remote and local). I also added an announcement @LocalBeanfor access to a bean with a view without an interface.

@Stateless
@LocalBean
public class WeatherDataBean implements WeatherDataBeanRemote, WeatherDataBeanLocal {
    @Inject
    private EntityManager entityManager;

    public WeatherDataBean () {

    }
    // ....attributes, getter & setter methods ....
}

I use @Injectfor this reason from this J8SS AS7 quick start example :

We use the Resource Maker pattern from CDI to the alias of the old-fashioned entity manager @PersistenceContext injection to the CDI style injection. This allows you to use a consistent embedding style (@Inject) throughout the application.

Now previously I used:

@PersistenceContext(unitName="WeatherStationJPA")
private EntityManager entityManager;

In EJB and it works without any problems. But with annotation, @InjectI get this error:

WELD-001408 [EntityManager] [@Default] [[field] @Inject private ejb.WeatherDataBean.entityManager]

:

public class Resources {
     @SuppressWarnings("unused")
     @PersistenceContext(unitName="WeatherStationJPA")
     @Produces
     private EntityManager entityManager;

     @Produces
     FacesContext getFacesContext() {
         return FacesContext.getCurrentInstance();
     }
}

, ?

EDIT: @LightGuard , , :

  • WeatherDataBean :

    import javax.ejb.LocalBean;
    import javax.ejb.Stateless;
    import javax.inject.Inject;
    
  • :

    import javax.enterprise.inject.Produces;
    import javax.faces.context.FacesContext;
    import javax.inject.Singleton;
    import javax.persistence.EntityManager;
    import javax.persistence.PersistenceContext;
    
+5
2

, ,

import java.util.logging.Logger;

import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.faces.context.FacesContext;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 * This class uses CDI to alias Java EE resources, such as the persistence context, to CDI beans
 * 
 * <p>
 * Example injection on a managed bean field:
 * </p>
 * 
 * <pre>
 * &#064;Inject
 * private EntityManager em;
 * </pre>
 */
public class Resources {
   // use @SuppressWarnings to tell IDE to ignore warnings about field not being referenced directly
   @SuppressWarnings("unused")
   @Produces
   @PersistenceContext
   private EntityManager em;

  // @Produces
  // public Logger produceLog(InjectionPoint injectionPoint) {
   //   return Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName());
  // }

   @Produces
   @RequestScoped
   public FacesContext produceFacesContext() {
      return FacesContext.getCurrentInstance();
   }

}
+5

, , beans.xml WEB-INF. beans.xml , WEB-INF. JBossAS CDI.

+6

All Articles