BeanFactory creation process
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 BeanDefinition
the right resource positioning process. Generally speaking, it is to find Javabean
the XML file that defines the information and encapsulate it into a Resource object .
BeanDefinition loading : The user-defined data structure is Javabean
represented 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#refreshBeanFactory
method in
the Step 2 : turn call more than one class of loadBeanDefinitions method -> AbstractXmlApplicationContext
-> AbstractBeanDefinitionReader
-> XmlBeanDefinitionReader
performed until XmlBeanDefinitionReader
the doLoadBeanDefinitions method of
the Step 3 : We focus on observation XmlBeanDefinitionReader
class registerBeanDefinitions method produces during heavy load times call, we locate the last
here we focus on two areas: a createRederContext method , it is a DefaultBeanDefinitionDocumentReader
class of registerBeanDefinitions method , first enter createRederContext method look
we can see that here Spring finished first NamespaceHandlerResolver
initialization.
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. BeanDefinition
after the object into a Map, BeanFactory
based on Map
the structural organization of these BeanDefinition
are.
You can DefaultListableBeanFactory
see 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! ! !