The creation process of the bean of Spring's DefaultListableBeanFactory

1. Introduction to
    DefaultListableBeanFactory DefaultListableBeanFactory is the core part of bean loading and the default implementation of Spring registration and loading. The inheritance relationship is as follows:

    AbstractAutowireCapableBeanFactory completes bean creation , attribute injection, aspect proxy generation , and bean life cycle management.

2. Source code analysis of AbstractAutowireCapableBeanFactory
    The doCreateBean method completes the creation .


    Multiple post processors are registered by default in the Spring container. The class that implements the InstantiationAwareBeanPostProcessor interface will call the corresponding implementation method before and after the bean is instantiated and initialized.
    1. createBeanInstance(): Instantiate beans through reflection.
    2. addSingletonFactory(): If it is a singleton, add it to the singleton pool.
    3. populateBean(): inject attribute object
        3.1 Traverse the BeanPostProcessor list and call back the postProcessAfterInstantiation() method.
        3.2 Traverse the BeanPostProcessor list and call back the postProcessPropertyValues() method.
             CommonAnnotationBeanPostProcessor : Injected @Resource annotated object.
             AutowiredAnnotationBeanPostProcessor : Injected @Autowired annotated object.
             RequiredAnnotationBeanPostProcessor verifies that @Required annotated methods are called.
    4. initializeBean(): Initialize the bean.
        4.1 Traverse the BeanPostProcessor list and call back the postProcessBeforeInitialization() method.
            ApplicationContextAwareProcessor: The callback implements the interface methods such as EnvironmentAware, EmbeddedValueResolverAware, ResourceLoaderAware, ApplicationEventPublisherAware, ApplicationContextAware, and injects the corresponding Environment, StringValueResolver, ResourceLoader, ApplicationEventPublisher, and ApplicationContext objects.
            ServletContextAwareProcessor: The callback implements the methods of ServletContextAware, ServletConfigAware and other interfaces, and injects the corresponding ServletContext and ServletConfig objects.
        4.2 If you implement the InitializingBean interface, call back the afterPropertiesSet() method of the bean.
        4.3 If the bean is configured with the initMethod attribute, execute the method specified by initMethod.
        4.4 Traverse the BeanPostProcessor list and call back the postProcessAfterInitialization() method.
            ApplicationListenerDetector: Register ApplicationListener.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326525568&siteId=291194637