0

I am new to Spring and I need some help to understand the following:

Here's what I know:

BeanFactoryPostProcessors affects BeanDefinition objects because they are run right after your configuration is read in. There are no bean instances created yet. So it can’t do anything to your objects instances yet.

postProcessBeforeInitialization defined in the BeanPostProcessor gets called (as the name indicates) before the initialization of beans

Question:

If the above is true, which means if both are called before initialization, then how is BeanFactoryPostProcessor different from the postProcessBeforeInitialization method of BeanPostProcessor ? Also, I would appreciate if you can provide a real life example of how both are used and how to decide which one to use, when. Thanks.

mcfred
  • 1,183
  • 2
  • 29
  • 68
  • `postProcessBeforeInitialization` is called before the bean is initialized, but after it's been instantiated. If you look at the Javadoc, you get access to the bean instance, it just hasn't been processed yet. The `BeanFactoryPostProcessors` only gives you access to the bean definitions. – Sotirios Delimanolis Jun 30 '17 at 15:38
  • How can something be instantiated before being initialized? And if you closed this question, then please post the original question link. That would be helpful. – mcfred Jun 30 '17 at 15:40
  • Refresh this page. It'll be at the top. Instantiation is the process of creating an instance of a class. Initialization is the process of preparing the state of the instance, that can be processing injection targets, invoking lifecycle methods, etc. – Sotirios Delimanolis Jun 30 '17 at 15:42
  • Thank you. So, does that mean that BeanFactorypostProcessor get's called before the bean is instantiated or at the time of instantiation? – mcfred Jun 30 '17 at 15:45
  • Before all of it. You can read the javadoc [here](http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/beans/factory/config/BeanFactoryPostProcessor.html#postProcessBeanFactory-org.springframework.beans.factory.config.ConfigurableListableBeanFactory-). The lifecycle is explained there. – Sotirios Delimanolis Jun 30 '17 at 15:46

0 Answers0