ServletContextListener 启动SPRING加载数据到缓存的应用

时间:2022-04-21 06:04:47

java 代码

public class LoadTreeForXML implements ServletContextListener {
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        ServletContext servletContext = servletContextEvent.getServletContext();
        ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext);

//将数据放到缓存中。
        servletContext.setAttribute("allNotLeafNodeList", "AAAAAAAAAAAAAAAAAAA");
        servletContextEvent.getServletContext().removeAttribute("allNotLeafNodeList");
    }

public void contextDestroyed(ServletContextEvent servletContextEvent) {
        System.out.println("关闭信息!");
    }