0

親 xml と、MBeanExporter のコンテキストで親の Bean をインポートする子 xml の両方で定義されたキーのマップ値をオーバーライドしようとしています。Bean の「parent」属性、「registrationBehaviorName」プロパティ、およびマップ自体の「merge」属性を使用して、いくつかの組み合わせを試しました (すべて以下のコードに存在します)。

親 XML

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">

    <bean id="parentExporter" class="org.springframework.jmx.export.MBeanExporter">
        <property name="autodetect" value="false" />
        <property name="beans">
            <map>
                <entry key="theKey" value-ref="parentValue" />
            </map>
        </property>
    </bean>

</beans>

子 XML

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">

    <import resource="classpath:/META-INF/parent-context.xml"/>

    <bean id="childExporter" parent="parentExporter" class="org.springframework.jmx.export.MBeanExporter">
    <property name="autodetect" value="false" />
    <property name="registrationBehaviorName" value="REGISTRATION_REPLACE_EXISTING"/>
    <property name="beans">
        <map merge="true">
            <entry key="theKey" value-ref="childValue" />
        </map>
    </property>
    </bean>

</beans>

親の場合はキー「theKey」の値「parentValue」を取得し、子の場合はキー「theKey」の値「childvalue」を取得しようとしています。現在、インターネットから収集された属性/プロパティの使用された組み合わせに応じて、2 つの異なる間違いが発生します...

No unique bean of type XXX is defined: expected single bean but found 2: parentValue,keyValue

またはBeanAlreadyExistsException。親子が私がやろうとしていることを達成するための最良の方法ではないことは承知していますが、この構造を変更できないより大きなコンテキストで作業しています (コードに含めなかった他の多くの Bean が現在)。

私がやろうとしていることは実際に可能ですか? 私は Spring の専門家ではなく、ドキュメントやその他のソースで有効な解決策を見つけることができませんでした。

4

0 に答える 0