The listener for the Web container Servletcontextlistener is primarily used to monitor container startup and when the destruction needs to do something, listeners will be able to use this.
Servletcontextlistener starts in spring and then starts again.
To implement a simple listener, you need to inherit the interface Servletcontextlistener:
* A Test Listener sample * @author Zhuli * @date 2014-7-26 */public class Testcontextlister implements Servletcontextlistener { @O Verride public void contextinitialized (Servletcontextevent sce) { System.out.println ("==================== ========== container Loading "); } @Override public void contextdestroyed (Servletcontextevent sce) { System.out.println ("==================== ========== container Destruction "); }}
Servletcontextlistener implements two interfaces, one is when the container starts, and the other is when the container is destroyed:
Public interface Servletcontextlistener extends EventListener {/** * Notification that the Web application initialization * * process is starting. * * All servletcontextlisteners is notified of the context * * Initialization before any filter or servlets in the web * * applic ation is initialized. * /public void contextinitialized (Servletcontextevent sce);/** * * Notification that servlet context was about to be shut down. * * All Servlets and filters has been destroy () Ed before any * * Servletcontextlisteners is notified of context * * Destruc tion. * /public void contextdestroyed (Servletcontextevent sce);}
Configuration in Web. xml:
<listener><listener-class>com.xxx.controller.web.testcontextlister</listener-class></ Listener>
When the container starts, it is seen in the log that the container starts:
============================== container loading 2014-07-26 08:54:01.302:info:/:initializing Spring frameworkservlet ' ApiServlet '
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
Java thorough-the listener specific explanation of the Web container Servletcontextlistener