Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

About Spring BeanFactory

Tags:

spring

Does every time I new an new BeanFactory the beans in the XML file are to be recreated? In other words, if I set an bean's scope to Singleton, I got the same Object even if I newed another BeanFactory?

like image 396
Sefler Avatar asked Jun 15 '09 08:06

Sefler


1 Answers

Summary: yes, for one BeanFactory, no, for creating a BeanFactory each time.


If you use scope="singleton", which is the default setting, you will get the same instance each time from the same BeanFactory.

Spring does not manage scope across multiple, unrelated, BeanFactory instances.

Why you would create multiple bean factories?

like image 190
Robert Munteanu Avatar answered Nov 11 '22 15:11

Robert Munteanu