覆盖没有别名(也是父对象)的spring bean [英] Override spring bean without an alias that is also the parent
问题描述
我在 module1-spring.xml -
<bean id="parent" class="com.Parent"/>
<bean id="service" class="com.Service">
<property name="parent" ref="parent"/>
</bean>
我想覆盖 module2-spring.xml -
<bean id="child" class="com.Child" parent="parent"/>
我希望在服务中传递child
,而不是parent
.
如果我将child
别名为parent
即
I want child
to be passed in service instead of parent
.
If I alias child
as parent
i.e.
<alias id="child" alias="parent"/>
然后,parent属性将读取子级而不是父级Bean,并且在服务器启动时失败,并显示错误-
then the parent attribute will read child instead of parent bean and fail on server startup with error-
BeanDefinitionStoreException:具有名称的无效bean定义 在类路径资源[module2-spring.xml]中定义的子级":无法 解决父bean定义父".
BeanDefinitionStoreException: Invalid bean definition with name 'child' defined in class path resource [module2-spring.xml]: Could not resolve parent bean definition 'parent'.
在父级也是子级父级中重写父级的正确方法是什么?
What is the correct way of overriding parent while its also the parent of child?
推荐答案
在 module2 中复制 service bean并注入 child 解决了该问题. .
module2-spring.xml-
Copying the service bean in module2 and injecting child fixed the issue.
module2-spring.xml-
<bean id="service" class="com.Service">
<property name="parent" ref="child"/>
</bean>
这篇关于覆盖没有别名(也是父对象)的spring bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!