在java web应用程序中安装bootstrup文件 [英] Setup bootstrup file in java web application

查看:222
本文介绍了在java web应用程序中安装bootstrup文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了有关引导此处的信息。如何在我的web应用程序中使用jsf,spring和hibernate编写bootstrup文件?是否需要在应用程序中设置bootstrup文件? >

Java web应用程序是由它们运行的​​web容器(例如Tomcat)引导的,并且您不必自己动手。

但是,如果您希望在应用程序启动时添加额外的操作(和/或应用程序关闭时要执行的清理操作),那么servlet API将提供上下文监听器机制。基本上,你必须创建一个实现 javax.servlet.ServletContextListener 的类,该类有两个方法, contextInitialized contextDestroyed ,它们在应用程序启动时分别关闭。



然后你必须在web.xml中添加配置这个类,类似这样:

 <听者GT; 
< description>我的上下文侦听器< / description>
< display-name>我的上下文侦听器< / display-name>
< listener-class>
com.acme.myapp.MyContextListener
< / listener-class>
< / listener>

(或者在JEE6中,您可以使用 javax.servlet.annotation.WebListener 注释而不是XML)



谷歌是你的朋友的细节,但这里有一些链接开始:



http://www.roseindia.net/servlets/ ServletContextListener-example.shtml



http://docs.oracle.com/javaee/5/tutorial/doc/bnafi.html


I read about bootstrapping here. How can I setup bootstrup file in my web application written with jsf,spring and hibernate.Is it necessary to setup bootstrup file in my application?

解决方案

Java web applications are "bootstrapped" by the web container in which they are run (e.g. Tomcat) and you don't have to do it yourself.

However, if you want to add additional operations to be executed when the application is started up (and/or clean-up operations to be executed when the application is shut down), the servlet API provides the "context listener" mechanism.

Basically, you have to create a class that implements javax.servlet.ServletContextListener which has 2 methods, contextInitialized and contextDestroyed, that are executed when the application is started up, respectively shut down.

You must then add configure this class in web.xml, with something like that :

<listener>
    <description>My Context listener</description>
    <display-name>My Context listener</display-name>
    <listener-class>
        com.acme.myapp.MyContextListener
    </listener-class>
</listener>

(Or in JEE6 you could use the javax.servlet.annotation.WebListener annotation instead of XML)

Google is you friend for the details, but here are some links to start with :

http://www.roseindia.net/servlets/ServletContextListener-example.shtml

http://docs.oracle.com/javaee/5/tutorial/doc/bnafi.html

这篇关于在java web应用程序中安装bootstrup文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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