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

 

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("关闭信息!");
    }

posted @ 2016-04-01 16:32  牧之丨  阅读(1016)  评论(0编辑  收藏  举报