这个问题困扰了我很长时间,所以我想我应该把它扔掉。也许 jetty 专家会看到它。
我有一个运行良好的 J2EE 应用程序。当我启动 jetty 服务器主机时,我看到所有正确的信息都来自日志控制台,包括下面代码中的“上下文已初始化”消息。
但是,如果我通过将 root.war 文件复制到 webapps 文件夹来部署应用程序的新版本,我会看到“上下文已初始化”日志,但启动会在那里停止,并且不会进一步启动。服务器没有响应,所以我必须在每次部署后重新启动它。
我的问题是,接下来在哪里查看以查找挂起的内容。 ServletContextListener.contextInitialized() 之后会发生什么
public class ApplicationListener implements ServletContextListener {
private static final Logger log = Logger.getLogger(ApplicationListener.class.getName());
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
log.info("Context Initialised"); //this is the last thing to come out of the log before it hangs if jetty is restarting due to a new .war file detection
}
当我从头开始启动jetty时 - 我看到上面的其余日志被吐出,这表明正常启动:
2015-12-05 12:40:33.214:INFO:oejdp.ScanningAppProvider:Deployment monitor /opt/nimbits/contexts at interval 1
2015-12-05 12:40:33.215:INFO:oejd.DeploymentManager:Deployable added: /opt/nimbits/contexts/javadoc.xml
2015-12-05 12:40:33.222:INFO:oejd.DeploymentManager:Deployable added: /opt/nimbits/contexts/test.xml
2015-12-05 12:40:33.233:INFO:oejw.WebInfConfiguration:Extract jar:file:/opt/nimbits/webapps/test.war!/ to /private/var/folders/x4/vh_dqlln1hn_vkk8jgz9tcf00000gn/T/jetty-0.0.0.0-8080-test.war-_-any-/webapp
2015-12-05 12:40:33.528:INFO:oejs.TransparentProxy:TransparentProxy @ /javadoc-proxy to http://download.eclipse.org/jetty/stable-8/apidocs
2015-12-05 12:40:33.557:INFO:oejs.AbstractConnector:Started SelectChannelConnector@0.0.0.0:8080
最佳答案
The Java EE 6 Tutorial声明以下有关 Servlet 生命周期的内容:
- If an instance of the servlet does not exist, the web container
- Loads the servlet class.
- Creates an instance of the servlet class.
- Initializes the servlet instance by calling the init method.
- Invokes the service method, passing request and response objects. (i.e. GET or POST requests)
EE 6 教程指出 ServletListener 对 Servlet init()
和 destroy()
调用进行“ react ”。这意味着您的监听器将在步骤 1.3 的 init()
完成后被调用。您可以尝试重写 servlet 的 init 方法并添加打印语句来自行检查。
鉴于上述情况,您的应用程序似乎在步骤 #2 上挂起,即调用服务方法本身 (GET/POST)。为了确定起见,我建议向 servlet init 和 doGet/doPost 方法添加额外的日志记录。如果这仍然不能解决您的问题,try enabling Jetty trace这样您就可以更详细地记录可能出现的问题。
关于java - Jetty 调用 ServletContextListener.contextInitialized() 后会发生什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34108794/