|
From: Luke T. <ne...@fr...> - 2004-10-15 21:23:41
|
Hi,
Are you loading the same resource twice? i.e. are parentResource and
childResource the same? AFAIK the "singleton" or "prototype" definition
only applies within a particular BeanFactory and defines the behaviour
of calls to getBean. So if you load the same set of beans twice, you
will end up with two "singleton" beans called "dao".
The child BF will only delegate to the parent if it can't find a bean of
the given name in its own list, so if the parent contains an identical
set of beans to the child then each will always return its own copy of a
particular bean.
Luke.
Andreas Rudolf wrote:
> Hi,
>
> no answer so far :-(
>
> Maybe my question wasn't clear enough.
>
> I have two BeanFactories:
>
> parentContext:
> <bean id="dao" class="example.DaoImpl"/>
>
> childContext:
> <bean id="service" class="example.ServiceImpl"/>
>
>
> BeanFactory parent = new
> XMLBeanFactory(parentResource);
> Dao dao1 = (Dao) parent.getBean("dao");
>
> BeanFactory child = new
> XMLBeanFactory(childResource,parent);
> Dao dao2 = (Dao ) child.getBean("dao");
>
>
> --> Result dao1 and dao2 are NOT the same. I expected
> that they must be the same
> if the bean is defined as a singleton.
>
> In AbstractBeanFactory.geBean(String name, Object[]
> args) you don't search a instance in the
> singletoncache
> of the parent beanfactory. Why? Is it an error ?
>
> Regards
> Andreas
>
>
>
>
--
Luke Taylor. Monkey Machine Ltd.
PGP Key ID: 0x57E9523C http://www.monkeymachine.ltd.uk
|