nerdexam
Broadcom-VMware

2V0-72.22PSE · Question #88

Which is the correct approach to register for a bean destruction callback?

The correct answer is B. Annotate the callback method with @PreDestroy. Annotating a method with @PreDestroy (option B) registers it as a destruction callback - Spring invokes this method just before the bean is removed from the container, allowing cleanup of resources like closing connections or releasing locks. Why the distractors are wrong: A…

Core Spring

Question

Which is the correct approach to register for a bean destruction callback?

Options

  • AAnnotate the callback method with @PostDestroy.
  • BAnnotate the callback method with @PreDestroy.
  • CAdd the @Lazy annotation to the bean configuration.
  • DConfigure the bean instance to use prototype scope.

How the community answered

(48 responses)
  • A
    2% (1)
  • B
    88% (42)
  • C
    4% (2)
  • D
    6% (3)

Explanation

Annotating a method with @PreDestroy (option B) registers it as a destruction callback - Spring invokes this method just before the bean is removed from the container, allowing cleanup of resources like closing connections or releasing locks.

Why the distractors are wrong:

  • A (@PostDestroy) - this annotation does not exist in the Java/Spring spec; it's a fabricated distractor that sounds plausible by analogy with @PostConstruct.
  • C (@Lazy) - controls when a bean is initialized (deferred until first use), not when or how it is destroyed.
  • D (prototype scope) - Spring does not manage destruction callbacks for prototype-scoped beans at all; only singleton-scoped beans get destruction lifecycle management by default.

Memory tip: Think of the "Pre/Post" pair as bookends around the bean's life: @PostConstruct fires after construction (setup), and @PreDestroy fires before destruction (teardown). "Pre" = before it's gone.

Topics

#Bean Lifecycle#Destruction Callbacks#@PreDestroy#Spring Container

Community Discussion

No community discussion yet for this question.

Full 2V0-72.22PSE Practice