The mind map for this article is mainly derived from reading the source code of the Spring framework and the Tiny-Spring project. Please feel free to point out any omissions

1. BeanFactory

1.1 the IOC

BeanFactory is a key interface in Spring, which is mainly used to read configuration and obtain beans. The mind map is as follows:

The constructor instantiates the corresponding BeanDefinitionReader, which gets the BeanDefinition

BeanFactory core function getBean(name)

1.2 AOP

In Spring, BeanPostProcessor is mainly used to enhance beans. AOP is also involved here. In Spring, AutoxyCreator is responsible for enhancing corresponding beans.

In Spring AOP use AspectJ style, specific implementation class for AspectJAwareAdvisorAutoProxyCreator, the mind map is as follows:

AspectJ defines a set of AOP convenience standards, as follows:

1.3 ApplicationContext

ApplicationContext is a higher-level interface built on top of the BeanFactory interface. In addition to the BeanFactory interface, it also provides:

  • Event mechanism
  • Identify description
  • The BeanFactory enhancement mechanism BeanFactoryPostProcessor is another application of the Factory pattern
  • Configuring Environment Information

Constructor of ApplicationContext

The core method of the ApplicationContext is the Refresh method, which has the following method mind map. The postProcessBeanFactory in the ApplicationContext defaults to an empty implementation. The BeanFactoryPostProcessors invokeBeanFactoryPostProcessors default to an empty array:

ObtainFreshBeanFactory and prepareBeanFactory are responsible for getting a new BeanFactory and making the necessary preparations

InvokeBeanFactoryPostProcessors implementation is as follows, please notice BeanPostProcessor spring BeanFactoryPostProcessor, are still under the corresponding call order is according to the following ways:

  • PriorityOrdered
  • Ordered
  • ordinary

2. SpringMVC

SpringMVC is a framework based on the Servlet specification, and its core is DispatcherServlet

3. SpringBoot

SpringBoot is based on ApplicationContext:

  • Add empty method implementations such as postProcessBeanFactory and onRefresh
  • BeanFactoryPostProcessor has been added to enhance The BeanFactory

One SpringBoot registered the BeanDefinitionRegistryPostProcessor, ConfigurationClassPostProcessor responsible for component scanning, and parsing the configuration class

In the perfect

References:

  • [tiny – spring] [github.com/code4craft/…].