springspring-bootspring-beanspring-context

Is BeanPostProcessor postProcessAfterInitialization needed only to work with proxy?


A bean implementing BeanPostProcessor is called when all bean definitions will have been loaded, but no beans will have been instantiated yet

BeanPostprocessor is executed after the bean object is created, as it can be executed before init() and after init().

Is BeanPostProcessor postProcessAfterInitialization needed only to work with proxy?

UPD: what we need 2 methods postProcessBeforeInitialization & postProcessAfterInitialization for? Why not just one postProcessInitialization ?


Solution

  • @Nullable
    default Object postProcessAfterInitialization(Object bean,
                                                            String beanName)
                                                     throws BeansException
    

    Apply this BeanPostProcessor to the given new bean instance after any bean initialization callbacks (like InitializingBean's afterPropertiesSet or a custom init-method). The bean will already be populated with property values. The returned bean instance may be a wrapper around the original.