Win a copy of Spark in Action this week in the Open Source Projects forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

@EJB giving NullPointerException

 
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.
 
Ranch Hand
Posts: 147
  • 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: 147
  • 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: 147
  • 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.
    Bookmark Topic Watch Topic
  • New Topic