-3

What does @ejb annotation do in Java?

Pls tell the exact meaning of @ejb annotation in Java.

user2663489
  • 11
  • 1
  • 1
  • try here: [What does the @EJBs annotation do?](http://stackoverflow.com/questions/12348542/what-does-the-ejbs-annotation-do) – q99 Aug 08 '13 at 07:30

1 Answers1

-3

The @EJB annotation (and @Resource, @WebServiceRef, etc.) serves two purposes:

It declares a reference in the component namespace. For example, @EJB(name="myEJB") creates a reference java:comp/env/myEJB. If you annotate a field and do not specify a name, then it creates a reference java:comp/env/com.example.MyClass/myField. If the annotation is declared on a field or setter method, then the container performs injection when the component is created. How the reference is resolved varies, independent of whether the reference is being resolved for a lookup("java:comp/env/myEJB") or due to injection:

If EE 6+ is used, the lookup attribute requires a JNDI lookup to resolve the target. Some application servers support mappedName, which is specified to be vendor specific. This is usually implemented by performing a lookup. Application servers support bindings at deployment time. This is usually implemented by performing a lookup. If no other binding information is provided and the bean interface (beanInterface or the field type) is only implemented by a single EJB in the application, then the EJB specification requires that it fall back to that. If no other binding information is provided and #4 cannot work, some application servers will attempt to perform a lookup in the server namespace based on the ref name (for example, java:comp/env/myEJB might cause a lookup of myEJB in the server namespace).

David Elliman
  • 1,379
  • 8
  • 15
  • Just a hint why this is downvoted: it's an almost complete copy of the accepted answer in the duplicate question. – Thomas Aug 08 '13 at 08:25
  • 1
    OK. Well I answered it concurrently with that comment and never saw it. I found the answer elsewhere, so the last answer was a cut and paste from the same source. Perhaps there was just one magnificent answer to everything, long ago, and everything since is a cut and paste of that. – David Elliman Aug 08 '13 at 11:17