Card 07/ 07

RecapDifficulty: Advanced1 min

What This Topic Established

Singleton is one shared instance for the application's whole life; prototype is a fresh one every request. Singleton is the default and usually right — until it holds mutable state two callers can both reach.

@PostConstruct and @PreDestroy both fire for a singleton. For a prototype, only @PostConstruct does — the container stops tracking a prototype once it hands it over, so cleanup becomes the caller's job.

A shorter-lived bean injected into a singleton needs a scoped proxy, or the singleton resolves it once, at startup, and every caller after the first sees something stale.