tags:

views:

140

answers:

2

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?

+3  A: 

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?

Robert Munteanu
Thank you very much.
Sefler
A: 

short answer: no

you can try it yourself by creating two BeanFactory, then two times the same bean and then:

assert bean1 == bean2;

or

assert bean1.equals(bean2);
dfa