Spring Source: IOC (LI)

Source: Internet
Author: User
Tags xml parser

First, Beandefinition

Beandefinition is the internal representation of the configuration file <bean> element label in the container. Creating the final beandefinition consists of two main steps:
1) using Beandefinitionreader to read the configuration information resource, the DOM object that parses the configuration information through the XML parser, simply generates the corresponding Beandefinition object for each <bean>. But the beandefinition generated here may be semi-finished, because in the configuration file, we may refer to the properties of the external properties file through placeholder variables, which have not been resolved in this step.
2) using the Beanfactorypostprocessor registered in the container to process the beandefinition of the semi-finished products, the configuration represented by the placeholder will be resolved to the final actual value, so that the beandefinition of the semi-finished product is finished.

Ii. Factorybean and Beanfactory

One is factory, which is the IOC container or object factory, and one is the bean. In spring, all beans are managed by beanfactory (also known as the IOC container). For Factorybean, however, this bean is not a simple bean, but a factory bean that produces or modifies the object's generation, which is implemented in a similar way to the factory pattern and decorator pattern in design mode. The Beanfactory interface designs the Getbean method, which is the primary method for using the IOC container API, and the Bean's acquisition is indexed by specifying a name.

beanfactory Inheritance system : http://mydream1987.iteye.com/blog/1151380

Autowirecapablebeanfactory→abstractautowirecapablebeanfactory→defaultlistablebeanfactory→xmlbeanfactory The implementation series of the IOC container. Xmlbeanfactory This IOC container can read beandefinition defined in XML form.

@Deprecated Public classXmlbeanfactoryextendsDefaultlistablebeanfactory {Private FinalXmlbeandefinitionreader reader =NewXmlbeandefinitionreader ( This); /*** Create A new xmlbeanfactory with the given resource, * which must is parsable using DOM. * @paramResource XML resource to load beans definitions from *@throwsBeansexception in case of loading or parsing errors*/     PublicXmlbeanfactory (Resource Resource)throwsbeansexception { This(Resource,NULL); }     /*** Create A new xmlbeanfactory with the given input stream, * which must is parsable using DOM. * @paramResource XML resource to load beans definitions from *@paramparentbeanfactory Parent Bean Factory *@throwsBeansexception in case of loading or parsing errors*/     PublicXmlbeanfactory (Resource Resource, Beanfactory parentbeanfactory)throwsbeansexception {Super(parentbeanfactory);  This. Reader.loadbeandefinitions (Resource); } }

To programmatically use the IOC container:

New Classpathresource ("Beans.xml"newnew  Xmlbeandefinitionreader ( Factory); Reader.loadbeandefinitions (res);

Third, IOC container initialization

The initialization of the IOC container includes the three basic processes of beandefinition resouce positioning, loading, and registration. The initialization of spring container is divided into three steps, which make the bean information positioning, parsing and registering. In the case of the bean information in the form of an XML file, spring first finds the location of the XML file, then reads the file, parses the file into the corresponding beandefinition, and finally registers the obtained beandefinition with Beanfactory.

From This sequence diagram we can see that the spring container initialization process is mainly done by four classes, we can refer to the following class of comments to understand the responsibilities of these classes:

    1. Xmlbeandefinitionreader: A beandefinitionreader FOR XML bean definition information that reads the de facto XML file to an implementation of the Beandefinitiondocumentreader interface.
    2. Beandefinitiondocumentreader: The service Provider Interface (SPI) used to parse the spring bean definition information, which is called by Xmlbeandefinitionreader when the DOM document is actually parsed.
    3. Beandefinitionparserdelegate: Stateful proxy class for parsing XML bean definition information. Responsible for the definition of a bean information parsing planning can beandefinition objects.
    4. Beandefinitionregistry: Responsible for registering the resulting bean definition information in the beanfactory.

Four

Spring Source: IOC (LI)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.