|
|
Hi,
A stupid question, which should be easy to answer. Is 'singleton' defined relative to the ApplicationContext or to the 'root' context? In other words, if I have two application contexts, each of which has a singleton bean 'X', would it be the same instance or not? I'm specifically interested in the case when configuration is done though XML, like:Code:
lt;beansgt; lt;bean id=quot;context_ONEquot; lazy-init=quot;truequot; class=quot;org..context.support.ClassPathXmlApplicationContextquot;gt; lt;constructor-arggt; lt;listgt; lt;valuegt;classpath:com/artilekt/modules/beans.xmllt;/valuegt; lt;/listgt; lt;/constructor-arggt; lt;/beangt;
lt;bean id=quot;context_TWOquot; lazy-init=quot;truequot; class=quot;org..context.support.ClassPathXmlApplicationContextquot;gt; lt;constructor-arggt; lt;listgt; lt;valuegt;classpath:com/artilekt/modules/beans.xmllt;/valuegt; lt;/listgt; lt;/constructor-arggt; lt;/beangt;
lt;/beansgt;
where com/artilekt/modules/beans.xml looks like:
Code:
lt;beansgt; lt;bean id=quot;sampleBeanquot; class=quot;java.lang.Objectquot;/gt;
lt;/beansgt;
So, would I totally have two separate instance of 'sampleBean' (one in 'context_ONE' and another one in 'context_TWO') or it would be the same object?
Thanks.
Spring singletons are relative to their context so the two beans would not be the same.
This thread might help: showthread.php?t=25763 |
|