Which environment annotation, when declared within the FooBean bean class, is equivalent to the ejb-local-ref shown above?

A developer writes a stateless session bean FooBean and uses its deployment descriptor to
declare a local ejb dependency on a stateful session bean in the same ejb-jar.

Which environment annotation, when declared within the FooBean bean class, is equivalent to the
ejb-local-ref shown above?

A developer writes a stateless session bean FooBean and uses its deployment descriptor to
declare a local ejb dependency on a stateful session bean in the same ejb-jar.

Which environment annotation, when declared within the FooBean bean class, is equivalent to the
ejb-local-ref shown above?

A.
@EJB(beanName=�BarBean�)
Privateacme.Bar barRef;

B.
@EJB(name=�bar�, beanName=�BarBean�)
Privateacme.Bar barRef;

C.
@EJB(name=�barRef�, beanName=�BarBean�)
Private acme.Bar bar;

D.
@EJB(name=�ejab/barRef�, beanName=�BarBean�)
Private acme.Bar bar;

Explanation:
name is barRef
Example:
ejb-local-ref
share [gp] share [fb] share [tw] contribute
Via annotation
Usable by EJB, Interceptor, Servlet, Filter, or Listener
packageorg.superbiz.refs;

importjavax.ejb.EJB;
importjavax.ejb.Stateless;
importjavax.naming.InitialContext;
@Stateless
@EJB(name=”myFooEjb”,beanInterface=FooLocal.class)
publicclassMyEjbLocalRefBeanimplementsMyBeanInterface{
@EJB
privateBarLocalmyBarEjb;
publicvoidsomeBusinessMethod()throwsException{
if(myBarEjb==null)thrownewNullPointerException(“myBarEjb not injected”);
// Both can be looked up from JNDI as well
InitialContextcontext=newInitialContext();
FooLocalfooLocal=(FooLocal)context.lookup(“java:comp/env/myFooEjb”);
BarLocalbarLocal=(BarLocal)context.lookup(“java:comp/env/org.superbiz.refs.MyEjbLocalRefBea
n/myBarEjb”);
}
}
Via xml
The above @EJB annotation usage is 100% equivalent to the following xml.
<ejb-local-ref>
<ejb-ref-name>myFooEjb</ejb-ref-name>
<local>org.superbiz.refs.FooLocal</local>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>org.superbiz.refs.MyEjbLocalRefBean/myBarEjb</ejb-ref-name>
<local>org.superbiz.refs.BarLocal</local>
<injection-target>
<injection-target-class>org.superbiz.refs.MyEjbLocalRefBean</injection-target-class>
<injection-target-name>myBarEjb</injection-target-name>
</injection-target>
</ejb-local-ref>



Leave a Reply 1

Your email address will not be published. Required fields are marked *