ServletContextListener does not execute on deployment

你说的曾经没有我的故事 提交于 2021-01-27 13:48:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!