gpt4 book ai didi

java - 从工厂收到的 Spring 父 bean 是否有属性?

转载 作者:行者123 更新时间:2023-11-30 09:44:25 25 4
gpt4 key购买 nike

我有一个具有 map 属性的抽象父 bean。此 map 必须与子 map 属性合并。这是工作。但是当我把这个 bean 作为工厂内部时 - map 属性似乎消失了。我想内部 bean 的字段对 child 不可用。

<bean id="parent" factory-bean="factory"
factory-method="createbean">
<constructor-arg>
<bean abstract="true">
<property name="prop" >
<map>
<entry ............
.................
</map
...............

下一个bean:

  <bean id="child" parent="parent">

是否正确?谢谢。

最佳答案

这是一个工作示例:

<bean id="parent" abstract="true" factory-bean="factory" factory-method="createBean">
<constructor-arg index="0">
<props>
<prop key="One">one-value</prop>
<prop key="Three">three-value</prop>
</props>
</constructor-arg>
</bean>

<bean id="child" parent="parent">
<constructor-arg index="0">
<props merge="true">
<prop key="Two">two-value</prop>
<prop key="Three">not-three-value</prop>
</props>
</constructor-arg>
</bean>

当返回子 bean 时,传入的 Properties 对象将具有以下值:

One=one-value
Two=two-value
Three=not-three-value

请注意,“Three”键的值被覆盖了,因为它包含在子 bean 中

关于java - 从工厂收到的 Spring 父 bean 是否有属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7920542/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com