Java tutorial
/** * Copyright(c) Foresee Science & Technology Ltd. */ package com.icanft.common.startup; import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.context.ApplicationContext; import org.springframework.web.context.ContextLoaderListener; import org.springframework.web.context.support.WebApplicationContextUtils; import com.icanft.common.ContextUtil; /** * * <pre> * ?Spring DIContextLoaderListener * </pre> * * @author luoshifei luoshifei@foresee.cn * @version 1.00.00 * * <pre> * * ?: : : * </pre> */ public class ContextInit extends ContextLoaderListener { private static final Log log = LogFactory.getLog(ContextInit.class); private static ApplicationContext context; private static ServletContext servletContext; /** * ServletContext * * @return ServletContext */ public static ServletContext getServletContext() { return servletContext; } /** * Spring DI * * @return ApplicationContext */ public static ApplicationContext getContext() { return context; } /** * Spring DI * * @param ctx ApplicationContext */ public static void setContext(ApplicationContext ctx) { context = ctx; } /** * ?DI * * @param context ServletContextEvent */ public void contextInitialized(ServletContextEvent context) { final ServletContext servletContext = context.getServletContext(); this.servletContext = servletContext; super.contextInitialized(context); // FBRP setContext(WebApplicationContextUtils.getRequiredWebApplicationContext(context.getServletContext())); ContextUtil.setApplicationContext(ContextInit.context); // ?FBRP? ContextUtil.setApplicationPath(context.getServletContext().getRealPath("/")); LicenseColl licenseList = null; try { licenseList = (LicenseColl) ContextInit.getContext().getBean("fbrp_licenseColl"); } catch (Exception exe) { log.warn("License?"); } if (licenseList != null) { boolean licenseIsValid = ValidateLicense.validateLicense(licenseList, ContextUtil.getApplicationPath()); ContextUtil.put("licenseIsValid", licenseIsValid, ContextUtil.SCOPE_APPLICATION); } else { ContextUtil.put("licenseIsValid", true, ContextUtil.SCOPE_APPLICATION); } } /** * ?DI * * @param event ServletContextEvent */ public void contextDestroyed(ServletContextEvent event) { ServletContext servletContext = event.getServletContext(); log.info("?Portlet"); log.info("??Portlet"); super.contextDestroyed(event); } }