• Post Reply Bookmark Topic Watch Topic
  • New Topic

EJB 3.0 Annotation giving problem with servlets

 
adil qureshi
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi I created an EJB and tried to call it using EJB annotation ( as given in all books ) it worked.Then i created a servlet and tried to call the EJB using @EJB annotation it gave me a Null Pointer Exception however when i called it using JNDI reference it returned me proper result ,Can Anybody explain me reason for this , or i am doing something wrong
 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May be Java version is creating a problem
 
adil qureshi
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abhay Agarwal wrote:May be Java version is creating a problem

No dear this is surely not the case , i think its not able to inject dependency (EJB 3.0) ,but exactly i cant say....
 
Nick Potter
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is your servlet running in the same JVM as the EJB?
 
adil qureshi
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nick Potter wrote:Is your servlet running in the same JVM as the EJB?

I created an EAR file with a War file and an EJB module , deployed it in Glassfish.... @ejb gives me an error (Null Pointer ) when i try to call this EJB from my servlet but the same annotation run fine in the way its given in Manning Book , then I tried to call it using JNDI from servlet and whew !!! it worked , I cant understand why @EJb annotation is not working for me in servlet .....
 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again taking a guess
- Which version of JSP/Servlets are using to run your sample code ?

Refer to this URL
http://www.javabeat.net/articles/100-new-features-in-servlets-25-1.html

@EJB is supported in Servlets 2.5 and above
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!