gpt4 book ai didi

java - 在启动时中止 java webapp

转载 作者:搜寻专家 更新时间:2023-10-31 19:51:23 24 4
gpt4 key购买 nike

我的 webapp 是部署到 websphere 服务器中的更大 EAR 的一部分。服务器在同一虚拟服务器上托管许多其他应用程序。我的 webapp 在 servletContextListener->contextInitialized 方法中有一些初始化/健康检查。如果初始化/健康检查失败,我想让 webapp 不可用。这样做的可靠方法是什么?从 contextInitialized 中抛出 RuntimeException 就足够了吗? EAR 的其余部分是否仍然可用?谢谢。

最佳答案

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

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

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 中对其进行测试。

关于java - 在启动时中止 java webapp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/272194/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com