在启动时中止java webapp [英] Abort java webapp on startup

查看:131
本文介绍了在启动时中止java webapp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的webapp是部署到websphere服务器中的更大EAR的一部分。服务器托管同一虚拟服务器上的其他应用程序数。我的webapp在servletContextListener-> contextInitialized方法中进行了一些初始化/运行状况检查。如果初始化/运行状况检查失败,我想使webapp不可用。这样做的可行方法是什么?是否会在contextInitialized中抛出RuntimeException? EAR的其余部分是否仍然可用?谢谢。

My webapp is part of a larger EAR that is deployed into a websphere server. The server hosts number of other apps on the same virtual server. My webapp has some initialisation/health checks in a servletContextListener->contextInitialized method. I want to make the webapp unavailable if initialisation/health checks fail. What is a realiable way of doing this? Will throwing a RuntimeException from within contextInitialized suffice? Is the rest of the EAR still expected to be available? Thank you.

推荐答案

我建议从<抛出 RuntimeException code> ServletContextListener.contextInitialized 。

I'd recommend throwing a RuntimeException from ServletContextListener.contextInitialized.

Servlet 2.3对此并不十分清楚,但Servlet 2.4增加了以下细节: / p>

Servlet 2.3 wasn't very clear on this, but Servlet 2.4 added the following detail:



应用程序中另一个组件的
调用堆栈下不会发生一些异常。一个例子是
… ServletContextListener,

初始化…的
通知期间抛出未处理的异常。在这种情况下,
开发人员没有机会以
处理异常。容器
可能以HTTP
状态代码500响应所有后续请求
到Web应用程序,以指示
应用程序错误。

Some exceptions do not occur under the call stack of another component in the application. An example of this is a … ServletContextListener that throws an unhandled exception during a notification of servlet context initialization…. In this case, the Developer has no opportunity to handle the exception. The container may respond to all subsequent requests to the Web application with an HTTP status code 500 to indicate an application error.

由于它表示servlet引擎可能禁止访问应用程序,因此您可能会发现服务器执行其他操作。但是,Tomcat和WebLogic都禁用了应用程序,我能想到的唯一合理的事情就是忽略该异常。我看不到一个非常流行的容器—所以你最好自己在WebSphere中测试它。

Since it says that the servlet engine "may" disable access to application, you might find a server that does something else. However, Tomcat and WebLogic both disable the application, and the only other reasonable thing I can think of would be to ignore the exception. I can't see a container that did that being very popular—so you'd better test it in WebSphere yourself.

这篇关于在启动时中止java webapp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆