ServletContextListener不会在部署时执行 [英] ServletContextListener does not execute on deployment
问题描述
当我部署war文件时,我正在尝试初始化流对象.
I am trying to initialize a streaming object when my war file is deployed.
我编写了一个实现ServletContextListener的Initializer类,并在我的web.xml中添加了一个侦听器类标记.问题是,当我向应用程序发出第一个请求时发生了ContextInitialized事件,而不是在部署应用程序时发生了.
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?
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");
}
}
在web.xml中:
<listener>
<listener-class>thepackage.Initializer</listener-class>
</listener>
找到了解决方案并将其发布在下面.
EDIT 2: Found the solution and posted below.
推荐答案
该问题特定于Websphere Liberty.
The problem is Websphere Liberty specific.
在Websphere Server的server.xml(〜/wlp/usr/servers/{server-name}/server.xml)中添加以下内容:
Add the following to the server.xml (~/wlp/usr/servers/{server-name}/server.xml) of your Websphere Server:
<webContainer deferServletLoad="false"/>
有关更多信息: