Spring's IOC container initialization process

Source: Internet
Author: User

The initialization of the IOC container is initiated by the refresh () method, which marks the official launch of the IOC container.

Specifically, the boot process consists of three basic processes:

Resource positioning of 1.BeanDifinition

Loading and parsing of 2.BeanDifinition

3.BeanDifinition registration in the IOC container

It is important to note that spring separates the three processes and uses different modules, such as the corresponding Resourceloader, Beandifinitionreader and other modules, in such a practical way, Allows users to tailor and extend the three processes with greater flexibility.

Defines the initialization process for the IOC container that best suits you.

The first process: beandifinition resource positioning

This resource positioning refers to the beandifinition resource location, which is accomplished by resourceloader through a unified resource interface, This resource provides a unified interface for the use of various forms of beandifinition.

For these beandifinition forms of existence, I believe we will not feel unfamiliar. Like what

The bean definition information in the file system can be abstracted using Filesystemresource.

The bean definition information in the class path can be used Classpathresource.

This positioning process is similar to the process of searching for data in a container, and it is the same as when a bucket is loaded with water.

Second procedure: Loading of Beandifinition

The onboarding process is to represent the user-defined bean as the data structure inside the IOC container, and the internal structure of the container is beandifinition. Specifically, Beandifinition is actually an abstraction of the Pojo object in the IOC container, which allows the IOC container to easily manage the Pojo object, the bean, through this beandifinition-defined data structure.

The third process: beandifinition registration

This is done by invoking the beandifinitionregistry excuse. This registration process registers the beandifinition that are parsed during onboarding to the IOC container. In the reading source, the beandifinition is injected into a hashmap inside the IOC container, and the IOC container holds the beandifinition data through this hashmap.

The process of initializing the IOC container, which is mentioned here, generally does not include the implementation of bean dependency injection. In the IOC design, the bean-defined onboarding and dependency injection are two separate processes. Dependency injection typically occurs when the application first requests beans from the container through Getbean. (except with pre-instantiated configurations)

(This article is based on reading the notes of Spring Technology Insider.)

Spring's IOC container initialization process

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.