ClassPathXmlApplicationContext constructor, part of the logic is to each member variable initial value:

The refresh operation is then performed.

Get ConfigurableListableBeanFactory:

Beans from beans.xml, once parsed, are stored in BeanFactory member variables beanDefinitionMap.

So how is the bean definition in beans.xml parsed?

Into abstractApplicationContext look:

LoadBeanDefintions method:

Enter AbstractXmlApplicationContext loadBeanDefinitions method:

From the Beans. Read and parse the XML place bean definition: a reader. LoadBeanDefinitions (configLocations);

Recursive method is called AbstractBeanDefinitionReader loadBeanDefinitions:



We recursively call loadBeanDefinitions, which receives input parameters of type Resource:

Entered the XmlBeanDefinitionReader. LoadBeanDefinitions method:

To start IO operations on beans.xml:

Pass the inputSource returned by Java IO operations into doLoadDocument:

Parse Beans.xml using documentBuilder:

CountBefore is 0, and registerBeanDefinitions is performed:

In the registerBeanDefintions method, parsing is done through the XML API provided by org.w3c.dom.element:

Parsing is divided into preProcess, parseBeanDefinitions, and postProcess:

To enter the IF branch, a bean node is found in beans.xml:

This is what the beanDefinition looks like:

Beans in beans.xml are defined as follows:

For more of Jerry’s original articles, please follow the public account “Wang Zixi “: