Following the program entry above, let’s look at how Spring parses the default tags.

First, each node is iterated:

Then call the corresponding method based on the node type:

The main thing we care about is how the Bean label is parsed, so click here to see:

For example, if you need BeanDefinitionHolder, please call it a BeanDefinitionHolder. Just click inside to see what it does:

It’s clear that it’s holding a BeanDefinition object inside. We learned from Spring that it’s going to read XML files into memory, so it’s going to have to be stored in objects, which is the BeanDefinition. So we follow up parseBeanDefinitionElement ().

In fact, each Bean label is mapped to a BeanDefinition object.

Break this method into two sections:

1. Parse the attributes of the bean label and encapsulate them into a BeanDefinition

// create GenericBeanDefinition object (GenericBeanDefinition implementation class)
AbstractBeanDefinition bd = createBeanDefinition(className, parent);

// Parse the properties of the bean tag and set the parsed properties into the BeanDefinition object
parseBeanDefinitionAttributes(ele, beanName, containingBean, bd);
bd.setDescription(DomUtils.getChildElementValueByTagName(ele, DESCRIPTION_ELEMENT));
Copy the code

ParseBeanDefinitionAttributes (as) for each attribute assignment, simply look at a:

if (ele.hasAttribute(INIT_METHOD_ATTRIBUTE)) {
	String initMethodName = ele.getAttribute(INIT_METHOD_ATTRIBUTE);
	bd.setInitMethodName(initMethodName);
} else if (this.defaults.getInitMethod() ! =null) {
	bd.setInitMethodName(this.defaults.getInitMethod());
	bd.setEnforceInitMethod(false);
}
Copy the code

You take the value of the XML and assign it to the BeanDefinition object.

2. Parse the child tag of the bean label and encapsulate it into a BeanDefinition

// Parse the meta tags in the bean
parseMetaElements(ele, bd);

// Parse the lookup-method tag in the bean
parseLookupOverrideSubElements(ele, bd.getMethodOverrides());

// Resolve the event-method tag in the bean
parseReplacedMethodSubElements(ele, bd.getMethodOverrides());

// Parse the constructor-arg tag in the bean
parseConstructorArgElements(ele, bd);

// Parse the property tag in the bean
parsePropertyElements(ele, bd);
Copy the code