Does anyone know why it's so difficult to inject an EJB into a Servlet? I'm using JBoss 6.2. My handler variable is null no matter what I try.
@Local
public interface RequestHandlerInterface {
public String handleRequest(String authKey);
}
@Singleton
public class RequestHandler implements RequestHandlerInterface {
...
}
public class Test extends HttpServlet {
@EJB
private RequestHandlerInterface handler; //Always null
}
In application context:
<bean id="requestHandler" class="company.application.RequestHandler" />
In web.xml (v3.0):
<servlet>
<servlet-name>Test</servlet-name>
<servlet-class>company.test.Test</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Test</servlet-name>
<url-pattern>/Test</url-pattern>
</servlet-mapping>
<ejb-local-ref>
<ejb-ref-name>RequestHandler</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>company.application.RequestHandlerInterface</local>
</ejb-local-ref>
I've tried so many combinations, with every @EJB(...) option... any idea?
Note: It is all contained in a single WAR.
Note: I've tried private RequestHandler handler; instead of the interface.
Note: I've tried with (name="ejb/RequestHandler") and mappedName, beanName, lookup
Note: I've tried with @Remote and @Local, with ejb-local-ref and ejb-ref
Note:
JNDI bindings for session bean named RequestHandler in deployment unit deployment "company.war" are as follows:
java:global/company/RequestHandler!company.application.RequestHandlerInterface
java:app/company/RequestHandler!company.application.RequestHandlerInterface
java:module/RequestHandler!company.application.RequestHandlerInterface
java:global/company/RequestHandler
java:app/company/RequestHandler
java:module/RequestHandler