Anonymous | Login | Signup for a new account | 12-17-2024 11:03 PST |
Main | My View | View Issues | Change Log | Docs |
Viewing Issue Advanced Details [ Jump to Notes ] | [ View Simple ] [ Issue History ] [ Print ] | ||||||||
ID | Category | Severity | Reproducibility | Date Submitted | Last Update | ||||
0003863 | [Resin] | minor | always | 01-28-10 09:19 | 02-10-10 17:12 | ||||
Reporter | ferg | View Status | public | ||||||
Assigned To | ferg | ||||||||
Priority | normal | Resolution | fixed | Platform | |||||
Status | closed | OS | |||||||
Projection | none | OS Version | |||||||
ETA | none | Fixed in Version | 4.0.4 | Product Version | 4.0.2 | ||||
Product Build | |||||||||
Summary | 0003863: @Singleton injection | ||||||||
Description |
(rep by Wesley Wu) When a @ApplicationScoped/@Singleton bean is designed to be initialized after webapp starts (I.E. when first http request was fired) instead of being initialized during startup stage, in given circumstance, it won't be injected correctly. This is my test case: ========== StartBean =========== public class StartBean { @Inject FirstBean firstBean; } ========== FirstBean =========== public class FirstBean { @Inject SecondBean secondBean; } ========== SecondBean =========== public class SecondBean { @Inject ThirdBean thirdBean; @Inject FourthBean fourthBean; } ========== ThirdBean =========== public class ThirdBean { @Inject SingletonBean singletonBean; } ========== FourthBean =========== public class FourthBean { @Inject SingletonBean dao; } ========== SingletonBean =========== @Singleton //@Startup public class SingletonBean { } ========== MyServlet =========== public class MyServlet extends HttpServlet { @Inject StartBean startBean; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("hello"); } } ========= web.xml =========== <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" [^] xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" [^] xsi:schemaLocation="http://java.sun.com/xml/ns/javaee [^] http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" [^] version="2.5"> <servlet id="MyServlet"> <servlet-name>MyServlet</servlet-name> <servlet-class>com.mycompany.servlet.MyServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>MyServlet</servlet-name> <url-pattern>/MyServlet</url-pattern> </servlet-mapping> </web-app> ================================= The "http://localhost:8080/MyServlet" [^] request will produce this exception: com.mycompany.servlet.MyServlet.startBean: com.mycompany.beans.StartBean.firstBean: com.mycompany.beans.FirstBean.secondBean: com.mycompany.beans.SecondBean.fourthBean: com.mycompany.beans.FourthBean.singletonBean: java.lang.IllegalArgumentException: Can not set com.mycompany.beans.SingletonBean field com.mycompany.beans.FourthBean.singletonBean to com.mycompany.beans.FourthBean When I annotate the SingletonBean as @Startup, it's fine. (uncomment the //@Startup line in SingletonBean.java) Either @Singleton or @ApplicationScoped throws the exception. It's a weird bug, taking me nearly two days to reproduce it in such a simple test case. |
||||||||
Steps To Reproduce | |||||||||
Additional Information | |||||||||
Attached Files | |||||||||
|
Mantis 1.0.0rc3[^]
Copyright © 2000 - 2005 Mantis Group
28 total queries executed. 25 unique queries executed. |