EJB bean and CDI bean and injection

After reading this data

I am still confused about the following things, please correct me if I am wrong.

  • All classes in the same package as bean.xml are CDI beans except classes are annotated as session / message / singleton.
  • Only EJBs can be injected using @EJB (within another EJB), whereas both CDI bean and EJB bean can be injected using @inject (within an EJB bean or CDI bean).
  • the class is annotated as @Stateless (for example) which is injected using @Inject is still an EJB bean, not a CDI bean, and will still be container-managed EJB with all the consistency of federation and transactional.

Thank you so much.:)

+3


source to share


1 answer


I would make the following fixes:

  • All classes in the same archive as beans.xml are CDI beans, including EJBs.

  • Only EJBs can be injected using @EJB

    (within another EJB or any other EE managed entity, including CDI beans ), whereas CDI bean and EJB bean can be injected using @inject (within an EJB bean or CDI bean).

  • A class annotated with @Stateless (for example), which is injected with @Inject, is still an EJB bean , and can also be a CDI bean if there is a bean in the deployment archive ; regardless , it will still be managed by the EJB container with all the consistency of merge and transaction.



It is noteworthy that a CDI managed bean is anything that can be @Inject

ed into another CDI bean and can use itself @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 and etc.).

+5


source







All Articles