Details
-
Feature Request
-
Resolution: Unresolved
-
Major
-
6.0.0.M4
-
None
-
0
-
0%
Description
Injection of a CDI Managed Bean into a servlet works for servlets that are registered using web.xml, but fails for servlets that are registered using the addServlet() method of the servlet context. Supporting injection in both cases would be more consistent and more convenient for developers.
In order to demonstrate this issue, I created an Arquillian test for a managed JBoss M4 application server. The test deploys a war-file that contains two servlets. Both servlets refer to the same servlet class. The servlet class is very simple: it has a field into which a request scoped bean is injected, and it reports to the client whether or not this field contains a null value. The first servlet is defined in the web.xml file, the second servlet is registered programmatically by calling ServletContext.addServlet. The test cases show that the first servlet works as expected. However, the second servlet detects a null value in the field that should contain an injected instance of the request scoped bean. Steps for reproduction:
unpack the attached zip file
export JAVA_HOME = <home of your JDK>
export JBOSS_HOME = <root directory of your JBoss 6 M4 server>
mvn test