IOC container startup phase

For the IOC container to provide us with services, it needs to go through two stages:
① container startup stage
② bean instantiation stage

The container startup phase is mainly to provide drawings for the construction work before actually constructing the bean. For example <bean id="..." class="...">...</bean>, this is written manually by us, and ioc should convert it into a bean drawing: that is, convert it into a BeanDefinition , and then register the BeanDefinition to the BeanDefinitionRegistry .

Spring provides some container extension points in the container startup phase. We can do some operations on the extension points, such as doing some operations on BeanDefinition. BeanFactoryPostProcessor provides this functionality.

@FunctionalInterface
public interface BeanFactoryPostProcessor {

    /**
     * Modify the application context's internal bean factory after its standard
     * initialization. All bean definitions will have been loaded, but no beans
     * will have been instantiated yet. (所有的BeanDifinition已经被加载,但是还没有bean被实例化)
     * This allows for overriding or adding
     * properties even to eager-initializing beans.
     * @param beanFactory the bean factory used by the application context
     * @throws org.springframework.beans.BeansException in case of errors
     */
    void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException;

}

There can be multiple BeanFactoryPostProcessors for processing one after another, but there must be order, that is, the Ordered interface is implemented.

Mainly several BeanFactoryPostProcessor :
write picture description here

Guess you like

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