Bean lifecycle and callbacks
On This Lesson 4 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
name the four lifecycle stages.
Planned topics
- Stages: instantiation (constructor), injection of dependencies, initialization, destruction at shutdown.
@PostConstructruns after injection;@PreDestroyruns before the bean is removed.- Use callbacks for light setup and cleanup, not heavy work.
- Never use injected fields inside the constructor body of a field-injected bean: they are not set yet.
Draft outline details
Demonstration
a timeline: constructor → dependencies set → @PostConstruct → bean in use → @PreDestroy.
Check your understanding
Which runs first, @PostConstruct or injection?
Show answer
Injection.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.