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

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

问题描述

我的 web 应用程序是部署到 websphere 服务器的更大 EAR 的一部分.服务器在同一虚拟服务器上托管许多其他应用程序.我的 web 应用程序在 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.

推荐答案

我建议从 ServletContextListener.contextInitialized 中抛出一个 RuntimeException.

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

Servlet 2.3 对此不是很清楚,但 Servlet 2.4 添加了以下细节:

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

某些异常不会发生在另一个组件的调用栈应用.这方面的一个例子是…ServletContextListener 那个在 a 期间引发未处理的异常servlet 上下文的通知初始化….在这种情况下,开发商没有机会处理异常.容器可以响应所有后续请求到带有 HTTP 的 Web 应用程序状态码 500 表示应用错误.

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天全站免登陆