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 () {
}
}
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;