I have a doubt regarding injecting the Beans in the client code.
Following is the code:
In the above code, I want to get the MyBean instance using DI. I know how to get it through JNDI lookup. But I want to know in which cases I can use DI to get the Bean. I am getting nullpointerException if am using DI. [ ].
Everything else is simply ignored: an annotation has no logic at all. The ejb container looks at the annotations on ejbs and injects resources.
If you use annotations in a class of yours which is not explicitly managed by the container, it is simply ignored: for example, nothing prevents you from creating your own annotation class (there's a cool example on O'Reilly book)
Look at the below code:
In the above code I am getting Null pointer exception. What I am doing is, I have a jar file consists of Ejb bean, I have a war file consists of this servlet. I am making a Ear file and deployed it in Jboss.
If am using JNDI look up for getting the bean, it is working fine but if i am using @EJB, i am getting Null pointer. Can anyone helps me where I am doing mistake?
However when we started using DI with the latest stable version of JBoss (4.2.2) we found that DI of EJB references has limited support. Namely it is only supported for objects inside the EJB container. This means that while beans can refer to each other with the @EJB annotation, other managed objects like servlets and non-EJB web services must still use JNDI lookup to access any Enterprise Beans.
hope this solves your problem