In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces you how to initialize XmlBeanFactory, the content is very detailed, interested friends can refer to, hope to be helpful to you.
XmlBeanFactory inherits DefaultListableBeanFactory, and the diagram is as follows
Internally read the definition of bean from xml through XmlBeanDefinitionReader, that is, delegate to XmlBeanDefinitionReader,XmlBeanDefinitionReader to read the bean definition of xml, delegate the actual xml document to read to BeanDefinitionDocumentReader, this class loads an DOM document for BeanDefinitionDocumentReader to use, it registers the definition of bean with the factory of the given bean. When XmlBeanFactory is initialized, the loadBeanDefinitions of XmlBeanDefinitionReader is called, and the Resource object is internally constructed into an EncodedResource object. Call loadBeanDefinitions, internally add the EncodedResource object to the resourcesCurrentlyBeingLoade thread object, and construct the InputSource object through the EncodedResource object. When doLoadBeanDefinitions is called, the Document object is initialized internally, the Document object is constructed through documentLoader, registerBeanDefinitions is called, and the bean instance is registered internally through the BeanDefinitionDocumentReader object. The registerBeanDefinitions,BeanDefinitionDocumentReader calling BeanDefinitionDocumentReader is the default implementation of BeanDefinitionDocumentReader. This interface reads the bean definition according to the "spring-beans" DTD and XSD format (spring default xml bean definition format). The structure, elements and attributes required by the xml document are hard-coded in this class. First, get the root of the Document object and read the profile attribute of root. With this property, we can deploy two sets of configurations in the configuration file to apply to the production environment and the development environment. This makes it easy to switch between development and deployment environments, and the most commonly used is to replace different databases. ParseBeanDefinitions is to read xml. The parseDefaultElement method is used to resolve the root node or child node if it is the default namespace, otherwise the delegate.parseCustomElement method is used to resolve the custom namespace. The way to determine whether it is a default namespace or a custom namespace is to use node.getNamespaceURI () to get the namespace and compare it with the fixed namespace in spring. The parseDefaultElement method processes import, alias, bean, and beans tags.
First of all, we parse the bean tag. First, we delegate the parseBeanDefinitionElement method of the BeanDefinitionParserDelegate class to parse the element, and return the instance bdHolder of type BeanDefinitionHolder. After this method, the bdHolder instance already contains various attributes configured in our configuration file, such as class, name, id, alias and so on. When the returned bdHolder is not empty, if there is another custom attribute under the child node of the default tag, the custom tag needs to be parsed again. After the parsing is completed, the parsed bdHolder needs to be registered. Similarly, the registration Cao Zu entrusts the registerBeanDefinition method of BeanDefinitionReaderUtils, and finally sends out a response event to notify the relevant listener that the bean has been loaded.
The parseBeanDefinitionElement of the BeanDefinitionParserDelegate class extracts the id and name attributes of the element, further parses all other attributes and encapsulates them into the GenericBeanDefinition instance. If it is detected that bean does not specify beanName, then use the default rule to generate beanName for bean, and encapsulate the obtained information into the instance of BeanDefinitionHolder. The parseBeanDefinitionElement method creates a GenericBeanDefinition of type AbstractBeanDefinition for hosting attributes (Spring converts the configuration information in the configuration file into the internal representation of the container through BeanDefinition, and registers these BeanDefinition into BeanDefinitionRegistry, which is the first step), and then hard-codes the various attributes of the default bean, parses the metadata, parses the lookup-method and replaced-method attributes, parses the constructor parameters, parses the property child elements, and parses the qualifier sub-elements (this is the second part).
Parsing the various properties of the default bean is done through the method parseBeanDefinitionAttributes, parsing all the attributes of element, such as singleton, scope, abstract, lazy-init, autowire, depends-on, etc.
Parse the meta of the child element after parsing the attribute
Parsing child element lookup-method, also known as acquirer injection, is a special method injection, which declares a method to return a certain type of bean, but the actual bean to be returned is configured in the configuration file. This method can be used to design some pluggable functions, which the contact program depends on.
Parsing the child element replaced-method, you can replace the existing method with a new method at run time. Unlike the previous look-up, replaced-method can not only dynamically replace the returned entity bean, but also dynamically change the logic of the original method. Extract the name attribute (the old method to replace), extract the replacer attribute (the new replacement method)
On how to initialize XmlBeanFactory to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.