问题
I am trying to initialize a streaming object when my war file is deployed.
I wrote an Initializer class that implements ServletContextListener and added a listener-class tag to my web.xml. The issue is that the ContextInitialized Event occurs when I make the first request to my application and NOT when the app is deployed.
Is there a better way to initialize my application?
EDIT:
public class Initializer implements ServletContextListener{
@Override
public void contextDestroyed(ServletContextEvent arg0) {
System.out.println("Context Destroyed");
}
@Override
public void contextInitialized(ServletContextEvent arg0) {
System.out.println("Context Initialized");
}
}
From the web.xml:
<listener>
<listener-class>thepackage.Initializer</listener-class>
</listener>
EDIT 2: Found the solution and posted below.
回答1:
The problem is Websphere Liberty specific.
Add the following to the server.xml (~/wlp/usr/servers/{server-name}/server.xml) of your Websphere Server:
<webContainer deferServletLoad="false"/>
For more information:
http://www-01.ibm.com/support/knowledgecenter/SSEQTP_8.5.5/com.ibm.websphere.wlp.doc/ae/twlp_servlet_load.html?cp=SSEQTP_8.5.5%2F1-3-11-0-3-2-20-0
来源:https://stackoverflow.com/questions/32357661/servletcontextlistener-does-not-execute-on-deployment