一、前言
关于javg-rt-support源码包se.vgr.javg.util.webcomponent.support.ContextLoader类加载器,其基于spring的org.springframework.web.context.ContextLoader类加载器通过org.springframework.context.ConfigurableApplicationContext获取已初始化spring上下文继承父加载器的对象,详情参见源码说明。
二、源码说明
package se.vgr.javg.util.webcomponent.support;@b@@b@import javax.servlet.ServletContext;@b@import org.springframework.context.ApplicationContext;@b@import org.springframework.context.ConfigurableApplicationContext;@b@import org.springframework.web.context.WebApplicationContext;@b@import org.springframework.web.context.support.XmlWebApplicationContext;@b@@b@public class ContextLoader extends org.springframework.web.context.ContextLoader@b@{@b@ private ConfigurableApplicationContext parentApplicationContext;@b@@b@ public ContextLoader()@b@ {@b@ }@b@@b@ public ContextLoader(ConfigurableApplicationContext parentApplicationContext)@b@ {@b@ this.parentApplicationContext = parentApplicationContext;@b@ }@b@@b@ protected WebApplicationContext createWebApplicationContext(ServletContext servletContext, ApplicationContext parent)@b@ {@b@ if (this.parentApplicationContext == null)@b@ this.parentApplicationContext = SpringContextHelper.getContext();@b@@b@ XmlWebApplicationContext wac = new XmlWebApplicationContext(this) {@b@ public String[] getConfigLocations() {@b@ return null;@b@ }@b@@b@ };@b@ wac.setParent(this.parentApplicationContext);@b@ wac.setServletContext(servletContext);@b@ wac.refresh();@b@ return wac;@b@ }@b@}