WebxApplicationContext 覆盖spring默认的Configlocations。
package com.you.atlas.webx.context; import org.springframework.web.context.support.XmlWebApplicationContext; public class WebxApplicationContext extends XmlWebApplicationContext { public final static String WEBX_CONFIGURATION_LOCATION = "/WEB-INF/webx.xml"; public final static String WEBX_COMPONENT_CONFIGURATION_LOCATION_PATTERN = "/WEB-INF/webx-*.xml"; protected String[] getDefaultConfigLocations() { if (getNamespace() != null) { return new String[] { WEBX_COMPONENT_CONFIGURATION_LOCATION_PATTERN.replace("*", getNamespace()) }; } else { return new String[] { WEBX_CONFIGURATION_LOCATION }; } } }
WebxContextLoader 负责初始化 WebxApplicationContext
package com.you.atlas.webx.context; import javax.servlet.ServletContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContextException; import org.springframework.web.context.ContextLoader; public class WebxContextLoader extends ContextLoader { @Autowired protected Class<?> determineContextClass(ServletContext servletContext) throws ApplicationContextException { return getDefaultContextClass(); } protected Class<?> getDefaultContextClass() { return WebxApplicationContext.class; } }
WebxContextLoaderListener 负责初始化 WebxContextLoader
package com.you.atlas.webx.context; import org.springframework.web.context.ContextLoader; import org.springframework.web.context.ContextLoaderListener; public class WebxContextLoaderListener extends ContextLoaderListener{ protected ContextLoader createContextLoader() { return new WebxContextLoader(); } }