INT-1806: fix duplicate MBeans
This commit is contained in:
@@ -30,6 +30,8 @@ import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.support.GenericXmlApplicationContext;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.context.IntegrationObjectSupport;
|
||||
import org.springframework.integration.endpoint.AbstractEndpoint;
|
||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -142,6 +144,36 @@ public class MBeanExporterIntegrationTests {
|
||||
assertEquals(0, names.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDuplicateComponentNames() throws Exception {
|
||||
context = new GenericXmlApplicationContext(getClass(), "duplicate-components.xml");
|
||||
messageChannelsMonitor = context.getBean(IntegrationMBeanExporter.class);
|
||||
assertNotNull(messageChannelsMonitor);
|
||||
MBeanServer server = context.getBean(MBeanServer.class);
|
||||
Set<ObjectName> names = server.queryNames(ObjectName.getInstance("org.springframework.integration:type=ManagedEndpoint,*"), null);
|
||||
assertEquals(2, names.size());
|
||||
}
|
||||
|
||||
public static class BogusEndpoint extends AbstractEndpoint {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private IntegrationObjectSupport parent;
|
||||
|
||||
public void setParent(IntegrationObjectSupport parent) {
|
||||
this.parent = parent;
|
||||
setComponentName(parent.getComponentName());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doStart() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doStop() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class DateFactoryBean implements FactoryBean<Date> {
|
||||
|
||||
private Date date;
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<?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:context="http://www.springframework.org/schema/context" xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
|
||||
|
||||
<bean id="integrationExecutions" class="org.springframework.integration.monitor.IntegrationMBeanExporter">
|
||||
<property name="server" ref="mbeanServer" />
|
||||
</bean>
|
||||
|
||||
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
|
||||
<property name="locateExistingServerIfPossible" value="false" />
|
||||
</bean>
|
||||
|
||||
<bean id="parent" class="org.springframework.integration.monitor.MBeanExporterIntegrationTests$BogusEndpoint" />
|
||||
|
||||
<bean id="child" class="org.springframework.integration.monitor.MBeanExporterIntegrationTests$BogusEndpoint">
|
||||
<property name="parent" ref="parent"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user