Calling EJB 3.0 from Action Class(POJO)

Discussions

EJB design: Calling EJB 3.0 from Action Class(POJO)

  1. Calling EJB 3.0 from Action Class(POJO) (2 messages)

    Hi there, I am able call EJB3.0 stateless session bean from servlet client using @EJB annotation(no lookup). But when I try to call the same bean from action class, its throwing NullPointerException. @EJB private EJB3Sample ejb3Sample; When I print ejb3Sample object reference, its showing Null. 1)Can anyone explain the reason why the remote interface (POJI as per EJB3.0 docs) is null in action class whereas its available in servet? 2)can't we use @EJB in action class(POJO)? 3)We can use lookup in action class to get the bean, like...context.lookup("EJB3Sample#com.test.EJB3Sample") though this is working then whats the use of dependency injection? Thanks in advance, Rajesh

    Threaded Messages (2)

  2. The EJB3 container can only inject into servlets, ejbs, JSF pages(?) but not POJO's. That's the cause of the NPE and why it works in your servlet. /Sigmund
    Hi there,
    I am able call EJB3.0 stateless session bean from servlet client using @EJB annotation(no lookup). But when I try to call the same bean from action class, its throwing NullPointerException.

    @EJB
    private EJB3Sample ejb3Sample;
    When I print ejb3Sample object reference, its showing
    Null.

    1)Can anyone explain the reason why the remote interface (POJI as per EJB3.0 docs) is null in action class whereas its available in servet?
    2)can't we use @EJB in action class(POJO)?
    3)We can use lookup in action class to get the bean, like...context.lookup("EJB3Sample#com.test.EJB3Sample")
    though this is working then whats the use of dependency injection?

    Thanks in advance,
    Rajesh
  3. Thanks Sigmund[ Go to top ]

    Hi Sigmund, Thanks for your clarification. Rajesh