Initializing bean instances

After loading the bean definitions into the BeanFactory, the Spring IoC container instantiates the beans for the application; the following diagram shows the process flow:

As you can see in the preceding diagram, the bean initialization step is executed for each bean in the container. We can summarize the bean creation process as follows:

  • Each bean is eagerly instantiated by default. It is created in the right order with its dependencies injected unless marked as lazy.
  • Spring provides multiple BeanPostProcessor, so, each bean goes through a post-processing phase such as BeanFactoryPostProcessor, which can modify the bean definition. However, the BeanPostProcessor can change the instance of the bean.
  • After execution of this phase, the bean is fully initialized and ready for use. It is tracked by its id till the context is destroyed, except for the prototype beans.

In the next section, we'll discuss how to customize the Spring container by using a BeanPostProcessor.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset