Hi,
I have a servlet which calls a session EJB, the server is Glassfish v2:
@Remote
public interface HelloRemote {
public String sayHi();
}
@Stateless(mappedName = "HelloFEJB")
public class HelloFBean implements HelloRemote{
public HelloFBean() {
}
public String sayHi() {
return "Hi and Hello";
}
}
when the EJB is injected in the servlet class(Hellow), everything works, but
when the EJB is injected in another class(HelloEJBx), it has null pointer
exception, like below, why?
Thanks
public class Hellow extends HttpServlet {
... some methods
private String EJB_Hi() {
HelloEJBx ejb = new HelloEJBx();
return ejb.sayHi();
}
@EJB
private HelloRemote hello = null;
private String EJB_Hi2() {
return hello.sayHi();
}
protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
String hi = EJB_Hi2(); // this works
// String hi = EJB_Hi(); // this has null pointer at hello.sayHi() line
private class below
}
private class HelloEJBx {
@EJB
private HelloRemote hello = null;
public String sayHi() {
return hello.sayHi();
}
}
}
--
View this message in context: http://www.nabble.com/null-pointer-in-ejb-tp15282558p15282558.html
Sent from the java.net - glassfish users mailing list archive at Nabble.com.