Spring Source code reading: Design and Implementation of IOC containers (2) -- ApplicationContext

Source: Internet
Author: User

Spring Source code reading: Design and Implementation of IOC containers (2) -- ApplicationContext
Why is ApplicationContext recommended in Spring reference documents? What benefits does it bring to our applications? As one of BeanFactory implementations, how is it designed? What is the association between the WebApplictionContext \ XmlApplicationContext used in SpringMVC? ApplicationContext and BeanFactory: from the class diagram, we can see that ApplicationContext is presented as a sub-interface of BeanFactory. However, it adds new features based on BeanFactory: MessageSource (Message support, such as internationalization), ApplicationEventPublisher (event support), and ResourcePatternResolver (parsing resources ). The AbstractApplicationContext implementation class of ApplicationContext has basically implemented the ApplicationContext function. Copy the code/*** Abstract implementation of the {@ link org. springframework. context. applicationContext} * interface. doesn't mandate the type of storage used for configuration; simply * implements common context functionality. uses the Template Method design pattern, * requiring concrete subclasses to implement abstract methods. ** <p> In contrast to a plain BeanFactory, an ApplicationContext is supposed * To detect special beans defined in its internal bean factory: * Therefore, this class automatically registers * {@ link org. springframework. beans. factory. config. beanFactoryPostProcessor BeanFactoryPostProcessors}, * {@ link org. springframework. beans. factory. config. beanPostProcessor BeanPostProcessors} * and {@ link org. springframework. context. applicationListener ApplicationListeners} * which are de Fined as beans in the context. ** <p> A {@ link org. springframework. context. messageSource} may also be supplied * as a bean in the context, with the name "messageSource"; otherwise, message * resolution is delegated to the parent context. furthermore, a multicaster * for application events can be supplied as "applicationEventMulticaster" bean * of type {@ link org. springframework. context. event. appli CationEventMulticaster} * in the context; otherwise, a default multicaster of type * {@ link org. springframework. context. event. simpleApplicationEventMulticaster} will be used. ** <p> Implements resource loading through extending * {@ link org. springframework. core. io. defaultResourceLoader }. * Consequently treats non-URL resource paths as class path resources * (supporting full class path resource nam Es that include the package path, * e.g. "mypackage/myresource. dat "), unless the {@ link # getResourceByPath} * method is overwritten in a subclass. */The general meaning of the above description of the copy code is: 1. This class is an abstract Implementation of ApplicationContext, and does not specify which bean definition Configuration Policy to use. It implements Common implementations of various ApplicationContext. When designing this class, the template method design mode is used. Some methods need to be implemented in specific subclass. 2. Compared with BeanFactory, BeanFactoryPostProcessor, BeanPostProcessor, and ApplicationListener can be used as common Bean definitions in ApplicationContxt. 3. MessageSource can also be used in ApplicationContext, and the name used for using it is "messageSource ". You can also use ApplicationEventMulticaster (name is "applicationEventMulticaster"). If this parameter is not specified, SimpleApplicationEventMulticaster is used by default. 4. inherit DefaultResourceLoader to load resource files.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.