nerdexam
Oracle

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)…

Session Beans

Question

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?

Exhibit

1Z0-895 question #82 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)
  • A
    13% (5)
  • B
    5% (2)
  • C
    78% (31)
  • D
    5% (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

#@EJB annotation#ejb-local-ref#JNDI name#dependency injection

Community Discussion

No community discussion yet for this question.

Full 1Z0-895 Practice