1Z0-895 · Question #82
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…
The correct answer is C. @EJB(name="barRef", beanName="BarBean"). share [gp] share [fb] share [tw] contribute Usable by EJB, Interceptor, Servlet, Filter, or Listener packageorg.superbiz.refs; importjavax.ejb.EJB; importjavax.ejb.Stateless; importjavax.naming.InitialContext; @EJB(name="myFooEjb",beanInterface=FooLocal.class)…
Question
Exhibit
Options
- A@EJB(beanName="BarBean")
- B@EJB(name="bar", beanName="BarBean")
- C@EJB(name="barRef", beanName="BarBean")
- D@EJB(name="ejab/barRef", beanName="BarBean")
How the community answered
(40 responses)- A13% (5)
- B5% (2)
- C78% (31)
- D5% (2)
Explanation
share [gp] share [fb] share [tw] contribute Usable by EJB, Interceptor, Servlet, Filter, or Listener packageorg.superbiz.refs; importjavax.ejb.EJB; importjavax.ejb.Stateless; importjavax.naming.InitialContext; @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 The above @EJB annotation usage is 100% equivalent to the following xml. <ejb-ref-name>myFooEjb</ejb-ref-name> <local>org.superbiz.refs.FooLocal</local> </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>
Topics
Community Discussion
No community discussion yet for this question.
