I am working on a large Java EE 6 application that is deployed on JBoss 6 Final. My current tasks include using @Inject sequentially instead of @EJB, but I am facing some problems for some types of beans, namely @MessageDriven beans and beans using @Scheduled methods.
What will happen is that if I was not lucky with the timing (for @Schedule) or if there are messages in the MDB queues during the startup process, the beans instance will fail because the resources entered (which are EJBs themselves) are not yet connected.
Since I use @Inject, I assume that the EJB container considers my beans ready, since the container itself does not care about @Inject; it probably just assumes that since there are no @EJB injections, beans are ready to use. Introduced CDI proxies will fail because the resources for injection are not yet connected.
A tiny example:
@Stateless
@LocalBean
public class MySupportingBean {
public void doSomething() {
...
}
}
@Singleton
public class MyScheduledBean {
@Inject
private MySupportingBean supportingBean;
@Schedule(second = "*/1", hour = "*", minute = "*", persistent = false)
public void onTimeout() {
supportingBean.doSomething();
}
}
, , , beans, , , EJB, . , , MySupportingBean , onTimeout , MySupportingBean , MyScheduledBean . @EJB , MyScheduledBean , MySupportingBean .
, onTimeout, CDI MySupportingBean.
, , @Inject . , , @Schedule @MessageDriven @Inject? , , beans , beans , , EJB, @Schedule onMessage.