Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
356 views
in Technique[技术] by (71.8m points)

jakarta ee - Prevent Java EE application start on WebSphere on exception

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?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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).

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 (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...

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();
}

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.

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...