在启动时中止java

在启动时中止java

本文介绍了在启动时中止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:

由于它表示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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 21:02