Sobes.tech
Junior — Middle

Does the lifecycle of Spring - Prototype scope limit the creation of new instances for each request?

sobes.tech AI

Answer from AI

In Spring, the scope "prototype" means that a new instance is created each time the bean is requested. However, the lifecycle of such a bean is limited only to the moment of creation and initialization — Spring does not manage the further lifecycle of the object.

This means that Spring does not call destruction methods (e.g., @PreDestroy) for prototype beans, as it does not track them after they are issued. The management of the lifetime of such objects is the developer's responsibility.

Thus, the prototype scope does not limit the creation of new instances — on the contrary, it guarantees the creation of a new object with each request. But Spring does not control their further existence and destruction.

Does the lifecycle of Spring - Prototype scope limit… - sobes.tech