Is it possible to inject a @Produces into an @EJB?
Let's say I have a SLSB like:
@Local
public interface MyService {
void fetchWidget(Long id);
}
@Stateless
public class MyServiceBean implements MyService {
@Inject @MyData
EntityManager em;
public void fetchWidget(Long id) {
return em.find(Widget.class, id);
}
}
And a factory that declares my Producer:
@ApplicationScoped
public class EMFactory {
@Produces
@MyData
@PersistenceContext(unitName="theUnit")
static EntityManager entityManager;
}
Should this work assuming the @MyData annotation has been properly defined? I've tried, but haven't had any luck. Not entirely clear to me whether this is legal or not.
Rick
Yes, this should work.
What goes wrong?