Spring advanced source code notes: BeanFactory creation process comprehensive analysis of the accompanying code implementation!

One, get the BeanFactory sub-process

The timing diagram is as follows


This article references "Spring Advanced Source Notes", students who need to add assistant VX: C18173184271 free access

Spring interview feature article click here! ! !

Two, BeanDefinition loading analysis and registration sub-process

1. This sub-process involves the following key steps

Resource positioning : refers to BeanDefinitionthe right resource positioning process. Generally speaking, it is to find Javabeanthe XML file that defines the information and encapsulate it into a Resource object .

BeanDefinition loading : The user-defined data structure is Javabeanrepresented as the internal data structure of the IoC containerBeanDefinition .

Register BeanDefinition to the IoC container

2. Process analysis

1 the STEP : sub-process entry AbstractRefreshableApplicationContext#refreshBeanFactorymethod in

the Step 2 : turn call more than one class of loadBeanDefinitions method -> AbstractXmlApplicationContext-> AbstractBeanDefinitionReader-> XmlBeanDefinitionReaderperformed until XmlBeanDefinitionReaderthe doLoadBeanDefinitions method of

the Step 3 : We focus on observation XmlBeanDefinitionReaderclass registerBeanDefinitions method produces during heavy load times call, we locate the last

here we focus on two areas: a createRederContext method , it is a DefaultBeanDefinitionDocumentReaderclass of registerBeanDefinitions method , first enter createRederContext method look

we can see that here Spring finished first NamespaceHandlerResolverinitialization.

We then enter the registerBeanDefinitions method to track and call the DefaultBeanDefinitionDocumentReader#registerBeanDefinitions method.

Enter the doRegisterBeanDefinitions method.

Enter the parseBeanDefinitions method.

Enter the parseDefaultElement method.

Enter the processBeanDefinition method.

At this point, the registration process is over. BeanDefinitionafter the object into a Map, BeanFactorybased on Mapthe structural organization of these BeanDefinitionare.

You can DefaultListableBeanFactorysee the definition of this Map in

/** Map of bean definition objects, keyed by bean name. */
private final Map<String, BeanDefinition> beanDefinitionMap = new ConcurrentHashMap<>(256);

3. Timing diagram

If you need this full version of "Spring Advanced Source Notes", you only need to support my article.

A lot of support, you can get information for free-after three consecutive years (promise: 100% free)

Quick start channel: Add assistant VX: C18173184271 Get it for free! Full of sincerity! ! !

Spring interview feature article click here! ! !

Guess you like

Origin blog.csdn.net/Java_Caiyo/article/details/112954635