The most simple usage of Spring is to load xml definitions beans and use it.
We will go through the whole work flow based on spring unittest.
Go and check XmlBeanDefinitionReaderTests from package org.springframework.beans.factory.xml,
The method "withImport" show the simple workflow to load beans.
Load document
We will go through the whole work flow based on spring unittest.
Go and check XmlBeanDefinitionReaderTests from package org.springframework.beans.factory.xml,
The method "withImport" show the simple workflow to load beans.
Let’s jump inside loadBeanDefinitions. The overview workflow is compromised by 3 steps as following:
Validate Mode for resource.
The first main part is validate mode for resource.
As we know, XML had 2 type of validation: DTD VS XSD. The first step is check the file content to detect which mode we will parse the XML file.
Load document
Convert the input stream to xml document.
Register Bean Definition
CreateDelegate: Return BeanDefinitaionParseDelegate class. The actual implement class which parse the xml content and create Spring bean.
Before parse the actual bean, checking the profile at first. The working env should accept the profile of process defined in xml file.
After that, we finally reach the core function parseBeanDefinitions(root, this.delegate) to load beans. Let’s dive more into the this method.
The simple logic here is that the code visit all children of root element if spring default name space or parseCustomElement for customized spring definition. parseDefaultElement define the detailed behavior to parse.
BeanDefinitionParserDelegate: Stateful delegate class used to parse XML bean definitions.
Delegate.isDefaultNamespace: “http://www.springframework.org/schema/beans" or empty. The bean definition is the regular spring bean definition.
ParseDefaultElement will handle 4 types of spring beans .
- Import — importBeanDefinitionResource
- Alias — parseAliasRegistration
- Bean — parseBeanDefinition
- beans — doRegisterBeanDifinitions
- parseCustomElement will parse customized bean definition.
Comments
Post a Comment