Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

@EJB giving NullPointerException

 
Mishaal Khan
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a sample EJB3 project that has one Stateless session bean and an Application Client (main method) is calling its
method using JNDI lookup and its working fine.

But when I change the code and instead of JNDI lookup I inject EJB3 using @EJB annotation
its not able to find the bean and giving NullPointerException .

Just wondering is there any other setting requires to inject an EJB3 component.

Thanks.
 
xsunil kumar
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mishaal, you cannnot access @EJB in main method. @EJB will be injected by the server to your program and that program should be managed by the server itself(Servlets or EJBs).

So, in your main method you cannot access @EJB as its not available. So for main method you need to use only JNDI lookup.

-Sunil
 
Mishaal Khan
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply Sunil.

I also read the same description in a book that EJB can be injected in registered component in server.But
I am confused with this tutorial which is injecting EJB in a client program.

http://java.sun.com/javaee/5/docs/tutorial/doc/bnbnj.html


Do you think this application client can be registered in server?
Please verify how come it is possible.

Thanks.
 
xsunil kumar
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have seen the link provided by you. At this point, i am not very much sure now. So let me try above example and then see....

Thanks for above link

Sunil
 
xsunil kumar
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mishaal, i have tried the link given above and i am getting Null pointer exception there. I am not sure how sun has given this example.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic