SpringBoot基础篇(六)监听器Listener使用

待完善................................

根据监听的事件,可以把监听器分为三类:

(1)监听对象创建与销毁,如ServletContextListener ;

(2)监听对象域中属性的增加和删除,如:HttpSessionListener和ServletRequestListener;

(3)监听绑定到Session上的某个对象的状态,如ServletContextAttributeListener、HttpSessionAttributeListener、ServletRequestAttributeListener。

1、ServletContextListener源码说明

package javax.servlet;
import java.util.EventListener;

public interface ServletContextListener extends EventListener {

 //当Servlet容器启动web应用时调用该方法。在掉完该方法之后,容器再对Filter初始化,并对那些在web应用启动时就需要被初始化的Servlet进行初始化
 public void contextInitialized(ServletContextEvent sce);

 //当Servlet容器终止Web应用时调用次方法。在调用之前,容器先会销毁所有的servlet和filter过滤器
 public void contextDestroyed(ServletContextEvent sce);
}

猜你喜欢

转载自blog.csdn.net/u013089490/article/details/84617876