I'm using @EJB to get a instance of session bean. But I found that I always get NullPointer Exception.
My class is defined as following pattern.
@MessageDriven(mappedName = "jms/RequestQueue")
public class myMDB
public void onMessage(Message message)
Dispatcher dispatcher = new Dispatcher () ;
public class Dispatcher
@EJB(mappedName = "MySessionBean")
private MyRemoteInterface remote ;
public void dispatch()
I googled this issue, someone told that any annotation like @EJB can be used only in "managed classes" like Session Beans, Servlets etc. (Managed classes are those classes managed by the J2EE server.) Managed here means, lifetime controlled by server.
Is that true? But I thought that now that MDB is controlled by Container, the whole instance of classes which are stated inside MDB should be controlled by container as well.
But for my testing, seems like my guessing is not correct.
Is there anyone can explain why dosen't it work? And why Container is not able to controll class Dispatcher at my example?