ApplicationContext介绍

ApplicationContext介绍,第1张

概述1、ApplicationContext的所在的位置如下图   2、WebApplicationContext继承ApplicationContext   3、查看WebApplicationContext的实现类,常用的是XmlWebApplicationContext   XmlWebApplicationContext  /** * {@link org.springframework.

1、ApplicationContext的所在的位置如下图

 

2、WebApplicationContext继承ApplicationContext

 

3、查看WebApplicationContext的实现类,常用的是XmlWebApplicationContext

 

XmlWebApplicationContext 

/** * {@link org.springframework.web.context.WebApplicationContext} implementation * which takes its configuration from XML documents,understood by an * {@link org.springframework.beans.factory.xml.XmlBeanDeFinitionReader}. * This is essentially the equivalent of * {@link org.springframework.context.support.AbstractXmlApplicationContext} * for a web environment. * * <p>By default,the configuration will be taken from "/WEB-INF/applicationContext.xml" * for the root context,and "/WEB-INF/test-servlet.xml" for a context with the namespace * "test-servlet" (like for a dispatcherServlet instance with the servlet-name "test"). * * <p>The config location defaults can be overrIDden via the "contextConfigLocation" * context-param of {@link org.springframework.web.context.ContextLoader} and servlet * init-param of {@link org.springframework.web.servlet.FrameworkServlet}. Config locations * can either denote concrete files like "/WEB-INF/context.xml" or Ant-style patterns * like "/WEB-INF/*-context.xml" (see {@link org.springframework.util.PathMatcher} * javadoc for pattern details). * * <p>Note: In case of multiple config locations,later bean deFinitions will * overrIDe ones defined in earlIEr loaded files. This can be Leveraged to * deliberately overrIDe certain bean deFinitions via an extra XML file. * * <p><b>For a WebApplicationContext that reads in a different bean deFinition format,* create an analogous subclass of {@link AbstractRefreshableWebApplicationContext}.</b> * Such a context implementation can be specifIEd as "contextClass" context-param * for ContextLoader or "contextClass" init-param for FrameworkServlet. * * @author Rod Johnson * @author Juergen Hoeller * @see #setnamespace * @see #setConfigLocations * @see org.springframework.beans.factory.xml.XmlBeanDeFinitionReader * @see org.springframework.web.context.ContextLoader#initWebApplicationContext * @see org.springframework.web.servlet.FrameworkServlet#initWebApplicationContext */public class XmlWebApplicationContext extends AbstractRefreshableWebApplicationContext {	/** Default config location for the root context */	public static final String DEFAulT_CONfig_LOCATION = "/WEB-INF/applicationContext.xml";	/** Default prefix for building a config location for a namespace */	public static final String DEFAulT_CONfig_LOCATION_PREFIX = "/WEB-INF/";	/** Default suffix for building a config location for a namespace */	public static final String DEFAulT_CONfig_LOCATION_SUFFIX = ".xml";	/**	 * Loads the bean deFinitions via an XmlBeanDeFinitionReader.	 * @see org.springframework.beans.factory.xml.XmlBeanDeFinitionReader	 * @see #initBeanDeFinitionReader	 * @see #loadBeanDeFinitions	 */	@OverrIDe	protected voID loadBeanDeFinitions(Defaultlistablebeanfactory beanfactory) throws BeansException,IOException {		// Create a new XmlBeanDeFinitionReader for the given beanfactory.		XmlBeanDeFinitionReader beanDeFinitionReader = new XmlBeanDeFinitionReader(beanfactory);		// Configure the bean deFinition reader with this context‘s		// resource loading environment.		beanDeFinitionReader.setEnvironment(this.getEnvironment());		beanDeFinitionReader.setResourceLoader(this);		beanDeFinitionReader.setEntityResolver(new ResourceEntityResolver(this));		// Allow a subclass to provIDe custom initialization of the reader,// then proceed with actually loading the bean deFinitions.		initBeanDeFinitionReader(beanDeFinitionReader);		loadBeanDeFinitions(beanDeFinitionReader);	}	/**	 * Initialize the bean deFinition reader used for loading the bean	 * deFinitions of this context. Default implementation is empty.	 * <p>Can be overrIDden in subclasses,e.g. for turning off XML valIDation	 * or using a different XmlBeanDeFinitionParser implementation.	 * @param beanDeFinitionReader the bean deFinition reader used by this context	 * @see org.springframework.beans.factory.xml.XmlBeanDeFinitionReader#setValIDationMode	 * @see org.springframework.beans.factory.xml.XmlBeanDeFinitionReader#setdocumentReaderClass	 */	protected voID initBeanDeFinitionReader(XmlBeanDeFinitionReader beanDeFinitionReader) {	}	/**	 * Load the bean deFinitions with the given XmlBeanDeFinitionReader.	 * <p>The lifecycle of the bean factory is handled by the refreshbeanfactory method;	 * therefore this method is just supposed to load and/or register bean deFinitions.	 * <p>Delegates to a ResourcePatternResolver for resolving location patterns	 * into Resource instances.	 * @throws java.io.IOException if the required XML document isn‘t found	 * @see #refreshbeanfactory	 * @see #getConfigLocations	 * @see #getResources	 * @see #getResourcePatternResolver	 */	protected voID loadBeanDeFinitions(XmlBeanDeFinitionReader reader) throws IOException {		String[] configLocations = getConfigLocations();		if (configLocations != null) {			for (String configLocation : configLocations) {				reader.loadBeanDeFinitions(configLocation);			}		}	}	/**	 * The default location for the root context is "/WEB-INF/applicationContext.xml",* and "/WEB-INF/test-servlet.xml" for a context with the namespace "test-servlet"	 * (like for a dispatcherServlet instance with the servlet-name "test").	 */	@OverrIDe	protected String[] getDefaultConfigLocations() {		if (getnamespace() != null) {			return new String[] {DEFAulT_CONfig_LOCATION_PREFIX + getnamespace() + DEFAulT_CONfig_LOCATION_SUFFIX};		}		else {			return new String[] {DEFAulT_CONfig_LOCATION};		}	}}
总结

以上是内存溢出为你收集整理的ApplicationContext介绍全部内容,希望文章能够帮你解决ApplicationContext介绍所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1057244.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存