Schematic diagram of the structure of BeanFactory

1. Schematic diagram of the structure of BeanFactory



 

 2. Introduction of BeanFactory neutron interface

(1)ListableBeanFactory

This interface defines several methods for accessing the basic information of beans in the container, checking the number of beans [getBeanDefinitionCount], obtaining the configuration name of the bean, and checking whether the container contains a bean and other methods [containsBeanDefinition].
(2) HierarchicalBeanFactory

Parent-child cascading interface, the child container can access the parent container through the interface method.
(3) ConfigurableBeanFactory

One of the core interfaces, responsible for Bean initialization and attribute set and constructor injection.
(4) AutowireCapableBeanFactory

Define a method for automatically assembling container beans according to certain rules [that is, Autowire on the back Bean node].

 (5) BeanDefinitionRegistry
Each Bean node element in the Spring configuration file is represented by a BeanDefinition object in the Spring container, which describes the configuration information of the Bean. The BeanDefinitionRegistry provides a way to manually register BeanDefinition objects with the container.

3. Summary

From the above architecture we can see that. BeanFactory is a sophisticated machine. Each class is responsible for different things, but have they found out how to initialize an object of a class, and then find a place to store it, and what are the rules of storage based on byName, byType or constructor, etc., and then After confirming whether it is a single instance or multiple instances, and then after the Bean is loaded, the waiting is to register the BeanDefinition. Each Bean node corresponds to a BeanDefinition, which stores the Bean's name, classpath, and other related information. After being stored, it is finally stored in a BeanDefinitionMap. (Thinking about the problem in reverse: we know that to buy apples, many of the things we think of must be packed in a basket, and reflected in the program, we can find that if there are multiple data, or multiple records in the table are all in a set to load). So imagine that there are so many Bean nodes and one Bean node corresponding to one BeanDefinition in the Spring Bean registration process. It must be loaded with a List<BeanDefinitionMap>. The type of this Map is BeanDefinitionMao<String, BeanDefinition>.

Related Posts