package com.listener;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class ContextLoadListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent sce) {
//        ServletContextListener.super.contextInitialized(sce);
        ServletContext servletContext = sce.getServletContext();
        // 获取web.xml中默认设置参数
        String contextPath = servletContext.getInitParameter("contextConfigLocation");
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext(contextPath);
        servletContext.setAttribute("app",applicationContext);
        System.out.println("servletContextLoader");
    }
    @Override
    public void contextDestroyed(ServletContextEvent sce) {
    }
}
