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

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

问题描述

WebSphere 6.1.0.25是否有办法防止企业应用程序因异常而启动?我有一个ServletContextListener,我装配在contextInitialized()期间抛出RuntimeException。这会在服务器日志中生成堆栈跟踪,但是WebSphere控制台仍会将应用程序显示为成功启动,并且仍可以访问WAR资源。是否有一种机制可以阻止WebSphere标记应用程序成功启动,这可以由in-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设置为加载-startup,并从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.

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