首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

Servlet中获取Spring下上文对象

2012-10-23 
Servlet中获取Spring上下文对象.import javax.servlet.ServletContextEventimport javax.servlet.Servlet

Servlet中获取Spring上下文对象.

import javax.servlet.ServletContextEvent;import javax.servlet.ServletContextListener;import org.springframework.context.ApplicationContext;import org.springframework.web.context.WebApplicationContext;import org.springframework.web.context.support.WebApplicationContextUtils;public class SpringInit implements ServletContextListener {        private static WebApplicationContext springContext;        public SpringInit() {        super();    }        public void contextInitialized(ServletContextEvent event) {        springContext = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext());    }        public void contextDestroyed(ServletContextEvent event) {    }        public static ApplicationContext getApplicationContext() {        return springContext;    }    }

热点排行