|
I have a test application using @initialized and @Destoryed to monitor the scope context creation/destory.
|
HelloWorldExtensionTestServlet.java
|
@WebServlet("/hello")
|
public class HelloWorldExtensionTestServlet extends HttpServlet {
|
|
@Inject
|
HelloWorldExtensionBean hello;
|
|
private static EventMetadata beanStartMetaData;
|
private static EventMetadata beanStopMetaData;
|
|
private static final long serialVersionUID = 8549700799591343964L;
|
|
@Override
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
PrintWriter pw = response.getWriter();
|
pw.write(hello.hello());
|
pw.write(beanStartMetaData.getQualifiers().toString());
|
pw.write(beanStopMetaData.getQualifiers().toString());
|
pw.flush();
|
pw.close();
|
}
|
|
public static void onStart(@Observes @Initialized(RequestScoped.class) Object e, EventMetadata em) {
|
if (beanStartMetaData == null) {
|
System.out.println("Initialize Event request scope is happening");
|
beanStartMetaData = em;
|
}
|
}
|
public static void onStop(@Observes @Destroyed(RequestScoped.class) Object e, EventMetadata em) {
|
if (beanStopMetaData == null) {
|
System.out.println("Stop Event request scope is happening");
|
beanStopMetaData = em;
|
}
|
}
|
|
}
|
|
|
HelloWorldExtensionBean.java
|
@RequestScoped
|
public class HelloWorldExtensionBean {
|
|
public String hello() {
|
return "Hello World CDI 1.2!";
|
}
|
|
}
|
The application works fine. However, when I added a portal extension in the application, the app has stopped working and a NPE was thrown with the beanStartMetaData and beanStopMetaData null. It seems that the Initialized and Destoryed events are not fired.
|