Read Spring source (c)-classpathxmlapplicationcontext-getbean

Source: Internet
Author: User

This time the main look at the bean generation process, found a picture sequence diagram is very useful software plantuml, give full play to the programmer's ability, can be solved by the code of the other DAO??

1, call ApplicationContext Genbean method will call to Abstractapplicationcontext Getbean method, this method is actually referred to Beanfactory call Getbean

2, Defaultlistablebeanfactory will first get beannames according to the type, and then Abstractbeanfactory Dogetbean method according to Beanname call

3, Abstractbeanfactory first conversion beanname, and then look at the cache map to see if there is existing data, the first call will definitely return NULL. Then go to get rootbeandefinition, get dependson dependent beans, if there are dependent beans need to initialize the dependent bean first, then call the Getsingleton method to get the Singleton class

4, in the Defaultsingletonbeanregistry#getsingleton call Objectfactory#getobject to get the object, the function inside the main call Createbean to generate the object

5, Abstractautowirecapablebeanfactory#createbean

5.1. Resolvebeanclass gets the class of the bean according to beandefinition and loads

5.2, Docreatebean-->createbeaninstance here will get the method of building the bean, and based on whether there is a build method, whether there is a build parameter final bean construction mode

5.3. Autowireconstructor will build constructorresolver to build the bean

6, Constructorresolver#autowireconstructor, gets the build parameter from the Beandefinition, then obtains the existing constructor according to the Bean class and obtains the matching constructor according to the construction parameter value. After that is called the Simpleinstantiationstrategy#instantiate method, which is actually called Beanutils.instantiateclass (ctor, args) method, Using the reflection mechanism of Java to build an object, you get the object that needs to be built

7, then the bean-related postprocessor is called in Abstractautowirecapablebeanfactory, and then the Populatebean method is called.

8, Populatebean This method will determine whether the bean autowire, if it will be automatic injection, and finally call the Applypropertyvalues method, this method to see the name is also very good understanding, is the configuration of the property values to write. In this case, the bean's construction is basically complete, followed by writing the bean to the cache map, registering a singleton class, and so on.

Read Spring source (c)-classpathxmlapplicationcontext-getbean

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.