Spring Boot - Inversion of Control and Dependency InjectionHow can you ensure a Spring bean's destroy method is called when the application context closes?AUse @PostConstruct annotation on the destroy methodBImplement InitializingBean interfaceCSpecify the destroy method name in @Bean annotation or use @PreDestroyDCall the destroy method manually in the codeCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand destroy method registrationDestroy methods must be registered via @Bean(destroyMethod) or annotated with @PreDestroy.Step 2: Eliminate incorrect optionsInitializingBean is for init, manual calls are not automatic, and @PostConstruct is for init, not destroy.Final Answer:Specify the destroy method name in @Bean annotation or use @PreDestroy -> Option CQuick Check:Destroy method auto-call = @PreDestroy or destroyMethod [OK]Quick Trick: Use @PreDestroy or destroyMethod to auto-call destroy [OK]Common Mistakes:Confusing init interfaces with destroyExpecting manual callsMisusing @PostConstruct
Master "Inversion of Control and Dependency Injection" in Spring Boot9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallPerf
More Spring Boot Quizzes Application Configuration - Configuration precedence order - Quiz 14medium Exception Handling - @ExceptionHandler in controllers - Quiz 3easy Exception Handling - Problem Details for standard error format - Quiz 12easy Inversion of Control and Dependency Injection - @Autowired for dependency injection - Quiz 10hard Inversion of Control and Dependency Injection - Bean concept in Spring - Quiz 6medium Logging - Log formatting configuration - Quiz 5medium REST Controllers - @PathVariable for URL parameters - Quiz 1easy Request and Response Handling - Request validation preview - Quiz 7medium Spring Annotations - @PostConstruct and @PreDestroy - Quiz 4medium Spring Boot Fundamentals - Application.properties basics - Quiz 14medium