Currently I am trying to inject a stateless EJB into a CDI managed controller on Jboss 6 AS Final. The controller is managed in the context an accessible from the JSF pages
For those not having the luxury to change an ear to a war, I've found the following workaround:
@Inject
with the qualifier for those producer methods:Code:
// This bean is defined in the WEB module
@Stateless
public class EJBFactory {
@EJB
protected UserDAO userDAO;
// ~X other EJBs injected here
@Produces @EJBBean
public UserDAO getUserDAO() {
return userDAO;
}
// ~X other producer methods here
}
Now EJBs from anywhere in the EAR can be injected with:
// This bean is also defined in the web module
@RequestScoped
public class MyBean {
@Inject @EJBBean
private UserDAO userDAO; // injection works
public void test() {
userDao.getByID(...); // works
}
}
EJBBean is a simple standard qualifier annotation. For completeness, here it is:
@Qualifier
@Retention(RUNTIME)
@Target({TYPE, METHOD, FIELD, PARAMETER})
public @interface EJBBean {
}