0

I am using Mule/ Spring XML to define a set of spring beans.

I can create a bean using the following xml without wraping them in spring:beans element like so:

<spring:bean id="myFactoryBean" class="org.test.MyFactoryBean" />

But If I try referencing another bean it doesn't work unless I wrap both beans in the same spring beans:element like so:

<spring:beans>
     <spring:bean id="myFactoryBean" class="org.test.MyFactoryBean" />

        <spring:bean id="MyBean" class="org.test.MyBean" c:factory-ref="myFactoryBean" />
</spring:beans>

Why do I have to wrap them for them to have visibilty of each other? Is this a generic Spring XML requirement?

4

1 回答 1

3

我认为问题在于c命名空间仅在spring:beans元素范围内被识别。这同样适用于p命名空间和所有其他 Spring 命名空间,例如contextor util

如果c:factory-ref用经典constructor参数替换,即使spring:beans 没有被spring:beans元素包裹,它也应该可以工作。

但是,我个人建议作为一种好的做法,始终将您spring:bean的 s 放在spring:beans包装器元素中。它保持整齐的组织并启用所有 Spring 命名空间。

于 2013-05-20T13:41:26.003 回答