WEB容器监听器详解 ServletContextListener
来源:互联网 发布:量化对冲软件 编辑:程序博客网 时间:2024/05/16 01:44
WEB容器监听器ServletContextListener主要用来监听容器启动和 销毁的时候需要做一些操作,就可以使用这个监听器来做。
ServletContextListener在spring启动前启动。
我们实现一个简单的监听器,需要继承接口ServletContextListener:
- * 一个测试的监听器例子
- * @author zhuli
- * @date 2014-7-26
- */
- public class TestContextLister implements ServletContextListener {
- @Override
- public void contextInitialized(ServletContextEvent sce) {
- System.out.println("==============================容器装载");
- }
- @Override
- public void contextDestroyed(ServletContextEvent sce) {
- System.out.println("==============================容器销毁");
- }
- }
ServletContextListener 实现两个接口,一个是容器启动的时候,一个是容器销毁的时候:
- public interface ServletContextListener extends EventListener {
- /**
- ** Notification that the web application initialization
- ** process is starting.
- ** All ServletContextListeners are notified of context
- ** initialization before any filter or servlet in the web
- ** application is initialized.
- */
- public void contextInitialized ( ServletContextEvent sce );
- /**
- ** Notification that the servlet context is about to be shut down.
- ** All servlets and filters have been destroy()ed before any
- ** ServletContextListeners are notified of context
- ** destruction.
- */
- public void contextDestroyed ( ServletContextEvent sce );
- }
在web.xml中的配置:
- <listener>
- <listener-class>com.xxx.controller.web.TestContextLister</listener-class>
- </listener>
容器启动后,会在容器启动的日志中看到:
- ==============================容器装载
- 2014-07-26 08:54:01.302:INFO:/:Initializing Spring FrameworkServlet 'apiServlet'
0 0
- WEB容器监听器详解 ServletContextListener
- Java深入 - WEB容器监听器详解 ServletContextListener
- web上下文监听器ServletContextListener
- 监听器 ServletContextListener使用详解
- 预备知识: web监听器ServletContextListener
- tomcat监听器ServletContextListener加载web应用数据
- ServletContextListener监听器
- ServletContextListener监听器
- web容器监听器和log4j监听器
- 监听器ServletContextListener小记
- 监听器ServletContextListener小记
- 使用ServletContextListener监听器
- Spring ServletContextListener监听器
- 使用ServletContextListener监听器
- servletContextListener监听器调用问题
- ServletContextListener监听器解析
- Listener监听器(ServletContextListener)
- ServletContextListener,HttpSessionListener,ServletRequestListener监听器
- SpringMVC conflicts with existing, non-compatible bean definition of same name and class 的解决办法
- 迭代法求解线性方程组
- QCombobox应用QStyledItemDelegate小示例
- NDK开发系列之第二课C语言的基本语法与指针
- java代码的规范性
- WEB容器监听器详解 ServletContextListener
- Tomcat单机安装(centos/linux)
- C++异常以及错误处理
- Android——ListView使用过程中的常用属性(持续更新)
- sigemptyset、sigaddset、sigprocmask的用法
- 下载管理
- 多个if语句和多个if else语句的区别
- LoadRunner12.02学习指南
- [Three.js 文档注释]Introduction-Creating a scene