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