package cn.newgxu.bbs.common.listener; import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.web.context.ContextLoaderListener; import org.springframework.web.context.support.WebApplicationContextUtils; import cn.newgxu.bbs.common.util.Util; /** * * @author polly * @since 4.0.0 * @version $Revision 1.1$ */ public class StartupListener extends ContextLoaderListener implements ServletContextListener { private static final Log log = LogFactory.getLog(StartupListener.class); public void contextInitialized(ServletContextEvent event) { if (log.isDebugEnabled()) { log.debug("initializing context..."); } // call Spring's context ContextLoaderListener to initialize // all the context files specified in web.xml super.contextInitialized(event); ServletContext context = event.getServletContext(); setupContext(context); } public static void setupContext(ServletContext context) { log.debug(WebApplicationContextUtils .getRequiredWebApplicationContext(context)); Util.setWebApplicationContext(WebApplicationContextUtils .getRequiredWebApplicationContext(context)); } }