BeanFactoryPostProcessor and BeanPostProcessor in lifecycle events

前端 未结 4 1148
别跟我提以往
别跟我提以往 2020-12-02 09:19

I was trying to understand the difference between BeanFactoryPostProcessor and BeanPostProcessor.

I understood that BeanFactoryPostP

4条回答
  •  旧时难觅i
    2020-12-02 10:02

    Here is a flow diagram that might help to understand the spring bean initialisation life cycle.

    As we can see, the implementation of theBeanFactoryPostProcessor is executed before any spring bean instantiation, contrary to the BeanPostprocessor, where the implemented method will be executed only when the bean is instantiated.

    The source image is from the Spring 5 Design Patterns Book.

    I pick the explanation from the book:

    After loading the bean definitions from all styles of configurations, BeanFactoryPostProcessor comes into the picture to modify the definition of some beans, and then the container instantiates the beans. Finally, BeanPostProcessor works on the beans, and it can modify and change the bean object. This is the initialization phase.

提交回复
热议问题