Explain Bean lifecycle in Spring framework

Explain Bean lifecycle in Spring framework.

- The beans definition is found by the spring container from the XML file and instantiates the bean. All the properties specified in the bean definition are populated by spring using dependency injection. The bean’s Id is passed to setBeanName() method by the factory, and the factory calls setBeanFactory() is passed to itself, incase the bean implements the BeanFactoryAware interface. The init() method is invoked if specified. If any BeanPostProcessors are associated with the bean, the methods postProcessAfterInitialization() are invoked.

Explain Bean lifecycle in Spring framework.

1. The spring container finds the bean’s definition from the XML file and instantiates the bean.

2. Using the dependency injection, spring populates all of the properties as specified in the bean definition.

3. If the bean implements the BeanNameAware interface, the factory calls setBeanName() passing the bean’s ID.

4. If the bean implements the BeanFactoryAware interface, the factory calls setBeanFactory(), passing an instance of itself.

5. If there are any BeanPostProcessors associated with the bean, their post- ProcessBeforeInitialization() methods will be called.

6. If an init-method is specified for the bean, it will be called.

7. Finally, if there are any BeanPostProcessors associated with the bean, their postProcessAfterInitialization() methods will be called.
What is bean wiring?
What is bean wiring? - Bean wiring is the process of combining beans with Spring container...
Explain how to add a bean in spring application
How to add a bean in spring application - The id attribute of the bean tag specifies the name of the bean and the fully qualified class name is specified by the class attribute.....
What are singleton beans and how can you create prototype beans?
Singleton beans and prototype beans - All beans defined in the spring framework are singleton beans. The bean tag has an attribute by name ‘singleton’.....
Post your comment