Search⌘ K
AI Features

Bean Lifecycle: Prototype Scoped Beans

Understand the lifecycle of prototype scoped beans in Spring, including how the container creates these beans and your responsibility for their destruction. Learn through code examples how post-initialization methods are called but pre-destruction methods require manual handling outside the Spring container.

Lifecycle of prototype beans

Spring manages the entire lifecycle of singleton beans but it does not completely manage the lifecycle of prototype beans. This is because there might be a large number of prototype instances and the container can become overwhelmed keeping track of them.

Note: The Spring container creates the prototype beans and hands them over when requested. Thereafter, it ...