java - Jetty 调用 ServletContextListener.contextInitialized() 后会发生什么

标签 java jakarta-ee jetty

这个问题困扰了我很长时间,所以我想我应该把它扔掉。也许 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 生命周期的内容:

  1. If an instance of the servlet does not exist, the web container
    1. Loads the servlet class.
    2. Creates an instance of the servlet class.
    3. Initializes the servlet instance by calling the init method.
  2. 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/

相关文章:

java - 如何在java中生成一个5个字符的唯一字母数字值?

java - SLF4J : Class path contains multiple SLF4J bindings - Eclipse

eclipse - 在 Hibernate 中更改数据库时出现问题

java - Glassfish 中的 lib 文件夹中的文件夹有什么用,应该如何使用它们?

java - 从jetty 7升级到jetty 9

java - Jetty 和其他容器如何在遵守 Servlet 规范的同时利用 NIO?

java - 如何使用 wireshark 解密服务以服务 SSL 流量?

jakarta-ee - 如何从不同的JVM和服务器调用远程EJB?

java - 使用嵌入式 Jetty 提供静态文件

java - "Copy"Neo4j 中的弧线