【发布时间】:2012-08-17 19:25:31
【问题描述】:
我读到了关于引导 here 的信息。如何在使用 jsf、spring 和 hibernate 编写的 Web 应用程序中设置引导文件。是否有必要在我的应用程序中设置引导文件?
【问题讨论】:
标签: spring hibernate jsf web-applications bootstrapping
我读到了关于引导 here 的信息。如何在使用 jsf、spring 和 hibernate 编写的 Web 应用程序中设置引导文件。是否有必要在我的应用程序中设置引导文件?
【问题讨论】:
标签: spring hibernate jsf web-applications bootstrapping
Java Web 应用程序由运行它们的 Web 容器(例如 Tomcat)“引导”,您不必自己动手。
但是,如果您想添加在应用程序启动时执行的额外操作(和/或在应用程序关闭时执行的清理操作),则 servlet API 提供“上下文侦听器”机制.
基本上,您必须创建一个实现javax.servlet.ServletContextListener 的类,该类有两个方法,contextInitialized 和contextDestroyed,分别在应用程序启动和关闭时执行。
然后你必须在 web.xml 中添加配置这个类,像这样:
<listener>
<description>My Context listener</description>
<display-name>My Context listener</display-name>
<listener-class>
com.acme.myapp.MyContextListener
</listener-class>
</listener>
(或者在 JEE6 中,您可以使用 javax.servlet.annotation.WebListener 注释而不是 XML)
Google 是您了解详情的朋友,但这里有一些链接可以开始:
http://www.roseindia.net/servlets/ServletContextListener-example.shtml
【讨论】: