As you mentioned, annotating a field with @EJB injects EJB reference by looking up the JNDI name( specified by lookup property of @EJB)
@EJB on EJB class registers the EJB with a specific JNDI name (though it is registered by a default name in absence of 'name' property)
posted 7 years ago
Thank you so much for your reply
So you are saying that using the @EJB annotation with the name property on the class registers that particular EJB in the ENC with the provided name. So, that means that the @EJBs annotation shouldn't be used at the class level because there is only one EJB that you can register, and that is the annotated EJB. Is this right? I'm not sure. Because it doesn't make sense to use the @EJBs annotation for a field because you can only inject one EJB into a given field. So when do you use the @EJBs annotation?
I did a little more reading and tinkering with code and I figured something out. Ok, the @Resource annotation applied to a field injects the resource into that field. The @Resource annotation applied to the class adds the particular resource specified in the annotation into the ENC for the annotated EJB. The EJB can then look up that resource using JNDI and a JNDI name of "java:/comp/env/...". Each EJB in an EJB jar has its own ENC and a WAR has one ENC for everything in the WAR.