package cn.edu.tju.confiig;
import org.springframework.context.annotation.Configuration;
import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
@Configuration
public class MyServletRequestListener implements ServletRequestListener {
@Override
public void requestInitialized(ServletRequestEvent sre) {
HttpServletRequest httpServletRequest=(HttpServletRequest)sre.getServletRequest();
System.out.println(httpServletRequest.getServletPath() + "初始化");
}
@Override
public void requestDestroyed(ServletRequestEvent sre) {
HttpServletRequest httpServletRequest=(HttpServletRequest)sre.getServletRequest();
System.out.println(httpServletRequest.getServletPath() + "销毁");
}
}
基于配置文件的spring mvc 的话,需要配置@ComponentScan并配置web.xml,示例
<listener>
<listener-class>
cn.edu.tju.config.MyServletRequestListener
</listener-class>
</listener>