About Spring BeanFactory

Every time I have a new new BeanFactory beans in an XML file, do I need to recreate it? In other words, if I set the bean scope for Singleton, did I get the same object, even if I introduced a new BeanFactory?

+5
source share
2 answers

Summary: yes, for one BeanFactory, no, to create BeanFactoryevery time.


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

Spring does not control the scope for multiple unrelated BeanFactory instances.

Why did you create several bean factories?

+3
source

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); 
0
source

All Articles