29 December 2020

LifeCycle

  • Spring beans are initialized by the spring Applicationcontext and it also injects all the dependencies of  it.
  • The context is destroyed it also destroys all the initialized beans
  • Post initialization - Implement InitializingBean interface and afterPropertiesSet() method
  • Pre destroy - Implement DisposableBean interface and destroy() method
  • Post initialization and pre destroy methods are recommended since its tightly coupled
  • Providing init-method and destroy-method attribute values in the configuration file and this is the recommended approach.
  • As part of annotation @PostConstruct and @Predestroy annotations are used for post initialization and pre destroy.

Methods of bean life cycle

  • Setup: called when bean is loaded into the container
  • Teardown: called when the bean is unloaded into the container

No comments:

Post a Comment

Most views on this month