我在 module1-spring.xml 中有一个 bean-
<bean id="parent" class="com.Parent"/>
<bean id="service" class="com.Service">
<property name="parent" ref="parent"/>
</bean>
我想覆盖module2-spring.xml中的bean-
<bean id="child" class="com.Child" parent="parent"/>
我希望在服务中传递 child
而不是 parent
。
如果我将 child
别名为 parent
即
<alias id="child" alias="parent"/>
然后父属性将读取子 bean 而不是父 bean 并在服务器启动时失败并出现错误-
BeanDefinitionStoreException: Invalid bean definition with name 'child' defined in class path resource [module2-spring.xml]: Could not resolve parent bean definition 'parent'.
重写父级同时也是子级父级的正确方法是什么?
最佳答案
复制 module2 中的 service bean 并注入(inject) child 解决了这个问题。
module2-spring.xml-
<bean id="service" class="com.Service">
<property name="parent" ref="child"/>
</bean>
关于java - 覆盖没有别名的 spring bean,它也是父级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53606472/