Recall & Review
beginner
What is the purpose of the @PostConstruct annotation in Spring Boot?
It marks a method to be executed once immediately after the bean's initialization and dependency injection are complete.
Click to reveal answer
beginner
When is a method annotated with @PreDestroy called in a Spring Boot application?
It is called just before the bean is removed from the container, typically during application shutdown, to allow cleanup.
Click to reveal answer
intermediate
Can @PostConstruct and @PreDestroy methods have parameters?
No, methods annotated with @PostConstruct and @PreDestroy must have no parameters and return void.
Click to reveal answer
intermediate
How do @PostConstruct and @PreDestroy relate to the bean lifecycle in Spring Boot?
They provide hooks to run custom code right after bean creation (@PostConstruct) and right before bean destruction (@PreDestroy), managing setup and cleanup.
Click to reveal answer
intermediate
What happens if you forget to add @PreDestroy on a cleanup method in Spring Boot?
The cleanup code won't run automatically on shutdown, which may cause resource leaks like open connections or files.
Click to reveal answer
Which annotation runs a method after Spring Boot bean initialization?
✗ Incorrect
@PostConstruct runs after the bean is fully initialized.
What is the correct signature for a method annotated with @PreDestroy?
✗ Incorrect
@PreDestroy methods must have no parameters and return void.
When is a @PreDestroy method executed in Spring Boot?
✗ Incorrect
@PreDestroy runs just before the bean is destroyed.
What happens if you don't use @PostConstruct for initialization code?
✗ Incorrect
Without @PostConstruct, initialization code won't run automatically after dependencies are injected.
Which of these is NOT true about @PostConstruct and @PreDestroy?
✗ Incorrect
Methods annotated with these must have no parameters.
Explain how @PostConstruct and @PreDestroy annotations help manage a Spring Boot bean's lifecycle.
Think about when you want to prepare and clean up resources in your app.
You got /4 concepts.
Describe what could happen if you omit @PreDestroy on a method that closes resources in a Spring Boot app.
Consider what happens if you never close a door after entering a room.
You got /3 concepts.