6
votes

After reading these,

I'm still confused over the following things, please correct me if i am wrong.

  1. All classes within the same package as the bean.xml is a CDI bean except for classes annotate as session/message/singleton.
  2. Only EJB can be injected using @EJB(within another EJB), while both CDI bean and EJB bean can be injected using @inject(within EJB bean or CDI bean).
  3. class annotate as @Stateless(for example) that is injected using @Inject is still a EJB bean, not a CDI bean, and will still be managed by EJB container with all the goodness of pooling and transactional.

Thanks alot. :)

1

1 Answers

12
votes

I would make the following corrections:

  1. All classes within the same archive as the beans.xml is a CDI bean, including EJBs.

  2. Only EJB can be injected using @EJB (within another EJB or any other EE managed object including CDI beans), while both CDI bean and EJB bean can be injected using @inject (within EJB bean or CDI bean).

  3. A class annotated as @Stateless (for example) that is injected using @Inject is still an EJB bean, and it may also be a CDI bean if in a bean deployment archive; regardless, it will still be managed by EJB container with all the goodness of pooling and transactional.

Notably, a CDI managed bean is anything that can be @Injected into another CDI bean and can itself use @Inject, which is true for all EJBs, and @EJB can be used to inject an EJB into any other EE managed bean (EJB, servlet, CDI managed bean, etc.).