Skip to content
Ameen Abozaid
Planned lessonJNR-009-L05

Bean lifecycle and callbacks

  • Lesson 5 of 8
  • Junior
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.
  • @PostConstruct runs after injection; @PreDestroy runs 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.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.