有没有的Apache Tomcat 6.x的启动过程中执行code执行初始化程序等的手段? [英] Is there a means of executing code during the startup of Apache Tomcat 6.x to perform initialization routines, etc.?

查看:199
本文介绍了有没有的Apache Tomcat 6.x的启动过程中执行code执行初始化程序等的手段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的Tomcat服务器完成启动并开始提供我之前的Servlet初始化类的全局实例。如果此服务以某种方式初始化失败,我想整个启动过程失败,以及(或尽量接近这个成为可能;这将是毫无意义的服务器另行运行)。什么是我能做到这一点的最好方法是什么?

I want to initialize a global instance of a class before my Tomcat server completes startup and begins to offer my servlets. If this service somehow fails initialization, I'd like the entire startup sequence to fail as well (or as close to this as possible; it would be pointless for the server to be running otherwise). What's the best way I can accomplish this?

推荐答案

每个Web应用程序都有一个与之关联的ServletContext中。当应用程序被启动,并当该应用程序被关闭时破坏被创建ServletContext对象。 ServletContext作为拥有全球范围内,类似于在应用程序中一个全局变量。

Each web application has a ServletContext associated with it. The ServletContext object is created when the application is started and is destroyed when the application is shut down. A ServletContext has a global scope and is similar to a global variable in an application.

<一个href=\"http://www.javabeat.net/tips/178-servletcontextlistener-example.html\">http://www.javabeat.net/tips/178-servletcontextlistener-example.html

在这里完整的解释

<一个href=\"http://onjava.com/pub/a/onjava/2001/04/12/listeners.html\">http://onjava.com/pub/a/onjava/2001/04/12/listeners.html

这篇关于有没有的Apache Tomcat 6.x的启动过程中执行code执行初始化程序等的手段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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