Setup bootstrup file in java web application

…衆ロ難τιáo~ 提交于 2019-12-12 06:35:01

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/12071985/setup-bootstrup-file-in-java-web-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!