I have created an EAR with a web project, ejb3 project and the ejb client. I'm able to call the bean methods via injection in the servlet. I'm planning to use a ServiceDelegate which is a pojo to handle the bean invocation. So I'll call the delegate from my servlet and the delegate will call the appropriate beans and its methods.
But I'm unable to get the bean references in the delegate class which is in the web project. @EJB annotation returned a null reference. So I tried a JNDI lookup with java:comp/env/EARname/BeanName. But I always end up with naming exceptions.
Name comp/env/EARname not found in context "java:".
Please suggest me the correct way to call ejb3 beans via JNDI on Websphere 7 server.
Dependency injection in Java EE 5 and 6, works only for managed classes. In the servlet container, this is supported in a few types of classes, and not in all POJOs (unfortunately).
The Servlet Spec 2.5 sheds light on the classes for which the container must inject dependencies if they are present:
Component Type: Servlets
Classes implementing the following interfaces
Component Type: Filters
Classes implementing the following interfaces:
Component Type: Listeners
Classes implementing the following interfaces:
Therefore, if you have to resolve the issue with dependency lookups, you could adopt either of the following strategies: