Bean is an object in an application. A bean is created, used, and finally destroyed when its purpose is over. These are the different stages of a spring life cycle. The entire spring bean life cycle is supervised by the Spring IoC (Inversion of Control) container. That is why these beans are called spring beans.

source

The Life Cycle of a Spring Bean

source

In a spring bean life cycle, first of all, a bean is instantiated. After instantiation, a bean goes through a sequence of steps before being ready to be used. When a bean is no longer required for any function, it is destroyed.

Read: Top 18 Exciting Spring Projects Ideas & Topics For Beginners

Spring bean life cycle can be controlled in the following ways

  • Instantiation by using:
  • InitializingBean callback interface.
  • Custom init() method from the bean configuration file.
  • Aware interfaces for distinct actions.
  • PostConstruct and PreDestroy annotations.
  • Destruction
  • DisposableBean callback interface
  • Custom destroy() method from the bean configuration file.

#full stack development #spring bean life cycle #spring bean #spring #discuss

Spring Bean Life Cycle Explained [With Coding Example]
1.75 GEEK