Xml MBeanExporter映射的值重写

Xml MBeanExporter映射的值重写,xml,spring,jmx,mbeanexporter,Xml,Spring,Jmx,Mbeanexporter,我试图覆盖在父xml和子xml中定义的键的映射值,该子xml在MBeanExporter的上下文中导入父xml的bean。我尝试了几种组合,bean的parent属性、registrationBehaviorName属性以及映射本身的merge属性都出现在下面的代码中: 父Xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xm

我试图覆盖在父xml和子xml中定义的键的映射值,该子xml在MBeanExporter的上下文中导入父xml的bean。我尝试了几种组合,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>
或者是一个BeanalReadyExistenceException。我知道,父子关系可能不是实现我所要做的事情的最佳方式,但我正在一个更大的环境中工作,在这个环境中,这个结构无法修改,因为我没有在代码中包含很多其他bean


我想做的事情真的可能吗?我不是Spring专家,我一直无法找到关于文档和其他来源的有效解决方案

我想我不明白你想要实现什么。最后需要两个MBean还是一个?我希望子xml中的bean覆盖父xml中的bean。对两个bean使用相同的if似乎并没有起到作用。我可能错了,但您在stackoverflow上发布的配置只是这样做的:在MBean服务器上只注册一个名为thekey的MBean。我已经快速测试了您的配置,并且使用JConsole我看到正在注册子bean。也许你自己也可以尝试同样的方法:创建另一个项目,非常简单,使用你刚刚发布在stackoverflow上的配置,看看它是如何工作的。
<?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>
No unique bean of type XXX is defined: expected single bean but found 2: parentValue,keyValue