Reputation: 2237
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?
Upvotes: 6
Views: 625
Reputation: 116304
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);
Upvotes: 0
Reputation: 68268
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?
Upvotes: 3