How can you manage bean lifecycle events, such as initialization and destruction, in Spring Boot?

  • By using the @Bean annotation with @PostConstruct and @PreDestroy methods.
  • By declaring beans in an XML configuration file.
  • By using the @Service annotation with initMethod and destroyMethod attributes.
  • By configuring bean lifecycles in the main application class constructor.
You can manage bean lifecycle events, such as initialization and destruction, in Spring Boot by using the @Bean annotation along with @PostConstruct and @PreDestroy methods. These methods allow you to specify custom initialization and destruction logic for your beans. The other options mentioned (XML configuration, @Service with initMethod and destroyMethod, and configuring lifecycles in the main application class constructor) are not the recommended or common approaches for managing bean lifecycles in Spring Boot.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *