Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to let Spring initialize "prototype" beans only when it is got through getBean()?

Tags:

java

spring

I see that it initializes prototype beans on initial startup. How to prevent this ?

like image 644
EugeneP Avatar asked Dec 13 '22 22:12

EugeneP


1 Answers

This is not true, prototype-scoped beans are not initialized on startup, unless something else has a reference to them.

If you find that this is happening, then you must have a reference from a singleton bean to a protoype bean, and the initialization of the singleton bean is triggering the creation of the prototype.

like image 80
skaffman Avatar answered Apr 20 '23 00:04

skaffman