防止 Java EE 应用程序在 WebSphere 上启动异常 [英] Prevent Java EE application start on WebSphere on exception

查看:18
本文介绍了防止 Java EE 应用程序在 WebSphere 上启动异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WebSphere 6.1.0.25 有没有办法防止企业应用程序因异常而启动?我有一个 ServletContextListener,我操纵它在 contextInitialized() 期间抛出 RuntimeException.这会在服务器日志中生成一个堆栈跟踪,但是 WebSphere 控制台仍然显示应用程序成功启动,并且仍然可以访问 WAR 资源.是否有一种机制可以防止 WebSphere 将应用程序标记为可以由 WAR 工件生成的成功启动?

Is there a way with WebSphere 6.1.0.25 to prevent an enterprise application from starting due to an exception? I have a ServletContextListener that I rigged to throw a RuntimeException during contextInitialized(). This produces a stack trace in the server's log, however the WebSphere console still shows the application as starting successfully, and the WAR resources can still be accessed. Is there a mechanism that will prevent WebSphere as flagging the application from starting successfully that can be generated by in-WAR artifacts?

我还尝试将 servlet 设置为启动时加载,并从 init() 抛出异常,但这并没有产生我想要的效果.

I also tried setting a servlet to load-on-startup, and threw an exception from init(), and this did not produce the effect I was looking for.

推荐答案

是的,有一种方法可以做到,但我相信它仍然是特定于 WebSphere 的.几年前我们也遇到过同样的问题,即使发生重大错误,需要大量配置的应用程序仍会显示为已启动.唯一的判断方法是查看日志文件,看看是否发生了任何异常(并且 Web UI 工作得不太好).

Yes there is a way to do it but I believe it is still WebSphere specific. We had this same problem a few years ago, an application that required a lot of configuration would still show as started even when a major error occurred. The only way to tell was to look at the log file and see if any exceptions had occurred (and the web UI didn't work very well).

处理生命周期的标准方法似乎适用于大多数容器,是 ServletContextListener 但正如您发现的那样,没有处理启动错误的优雅方法.

The standard way to handle life-cycle, which seems to work on most containers, is the ServletContextListener but as you have found there is no graceful way to handle start-up errors.

在 WebSphere 中(对于一些版本)有启动 bean 的概念.与其像几年前那样详细解释它,不如看看这个链接 http://publib.boulder.ibm.com/inforcenter...

In WebSphere (for a few versions anyway) there is the concept of a startup bean. Rather than trying to explain it in detail as it was a couple of years ago that I did this you can have a look at this link http://publib.boulder.ibm.com/inforcenter...

这实质上允许您创建一个实现两个方法的 EJB bean:

This essentially allows you to create an EJB bean which implements two methods:

public boolean start() {
    return new Delegate().start();
}

public void stop() {
    new Delegate().stop();
}

如果从 start 方法返回 true 则返回成功启动,否则返回 false 将停止应用程序启动,因此在控制台中应用程序将指示它启动失败.我们实现了一个委托来完成这项工作,因此如果容器没有实现启动 bean,我们可以将它连接到启动 bean 或 ServletContextListener.

If you return true from the start method it returns a successful start, otherwise returning false stops the application starting so in the console the application will indicate that it failed to start. We implemented a Delegate to do the work so we could wire it up to either the startup bean or a ServletContextListener if the container didn't implement startup beans.

启动 bean 唯一的附加功能是,在 WebSphere 中,您需要在管理控制台中启用启动 bean 服务,否则它们将不会运行,您的应用程序也不会进行任何初始化,但在您使用时仍会显示为已启动尝试启动它.以上页面提供了有关如何执行此操作的信息.

The only additional thing with startup beans is that in WebSphere you need to enable the Startup beans service in the Administrative Console or else they won't run and your app won't do any initialisation but will still show as started when you try and start it up. There is information on how to do that from the above page.

我也确信 IBM 红皮书中有关于此的更多详细信息,但目前我似乎无法找到它.

I am also sure there is more detailed information in an IBM Redbook about this but at the moment I can't seem to locate it.

这篇关于防止 Java EE 应用程序在 WebSphere 上启动异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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