diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/ConnectionFactoryTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/ConnectionFactoryTests.java index ec499b2790..4c58f19e53 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/ConnectionFactoryTests.java +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/ConnectionFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -53,6 +53,7 @@ import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.BeanFactory; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEventPublisher; +import org.springframework.integration.channel.NullChannel; import org.springframework.integration.context.IntegrationContextUtils; import org.springframework.integration.ip.event.IpIntegrationEvent; import org.springframework.integration.ip.tcp.TcpReceivingChannelAdapter; @@ -128,6 +129,7 @@ public class ConnectionFactoryTests extends LogAdjustingTestSupport { when(bf.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME, TaskScheduler.class)).thenReturn(scheduler); serverFactory.setBeanFactory(bf); TcpReceivingChannelAdapter adapter = new TcpReceivingChannelAdapter(); + adapter.setOutputChannel(new NullChannel()); adapter.setConnectionFactory(serverFactory); adapter.start(); assertTrue("Listening event not received", serverListeningLatch.await(10, TimeUnit.SECONDS)); diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/IntegrationMBeanExportConfiguration.java b/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/IntegrationMBeanExportConfiguration.java index c64bc3f93e..ac947a28d9 100644 --- a/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/IntegrationMBeanExportConfiguration.java +++ b/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/IntegrationMBeanExportConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,6 @@ import java.util.List; import java.util.Map; import javax.management.MBeanServer; -import javax.management.MBeanServerFactory; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; @@ -37,6 +36,7 @@ import org.springframework.context.EnvironmentAware; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.ImportAware; +import org.springframework.context.annotation.MBeanExportConfiguration.SpecificPlatform; import org.springframework.context.annotation.Role; import org.springframework.context.expression.StandardBeanExpressionResolver; import org.springframework.core.annotation.AnnotationAttributes; @@ -55,6 +55,7 @@ import org.springframework.util.StringUtils; * {@link EnableIntegrationMBeanExport} annotation. See its javadoc for complete usage details. * * @author Artem Bilan + * @author Gary Russell * @since 4.0 */ @Configuration @@ -143,7 +144,10 @@ public class IntegrationMBeanExportConfiguration implements ImportAware, Environ exporter.setServer(bean); } else { - exporter.setServer(MBeanServerFactory.createMBeanServer()); + SpecificPlatform specificPlatform = SpecificPlatform.get(); + if (specificPlatform != null) { + exporter.setServer(specificPlatform.getMBeanServer()); + } } } diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/MBeanExporterIntegrationTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/MBeanExporterIntegrationTests.java index 426037ce17..c4faf1e950 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/MBeanExporterIntegrationTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/MBeanExporterIntegrationTests.java @@ -15,6 +15,7 @@ package org.springframework.integration.monitor; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -33,14 +34,18 @@ import org.springframework.aop.framework.Advised; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.Lifecycle; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.support.GenericXmlApplicationContext; import org.springframework.integration.channel.AbstractMessageChannel; import org.springframework.integration.channel.QueueChannel; +import org.springframework.integration.config.EnableIntegration; import org.springframework.integration.context.IntegrationObjectSupport; import org.springframework.integration.context.OrderlyShutdownCapable; import org.springframework.integration.endpoint.AbstractEndpoint; import org.springframework.integration.endpoint.MessageProducerSupport; import org.springframework.integration.endpoint.SourcePollingChannelAdapter; +import org.springframework.integration.jmx.config.EnableIntegrationMBeanExport; +import org.springframework.integration.test.util.TestUtils; import org.springframework.jmx.export.annotation.ManagedResource; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; @@ -224,6 +229,28 @@ public class MBeanExporterIntegrationTests { assertEquals(2, names.size()); } + @Test + public void testSingleMBeanServer() { + AnnotationConfigApplicationContext ctx1 = new AnnotationConfigApplicationContext(Config1.class); + AnnotationConfigApplicationContext ctx2 = new AnnotationConfigApplicationContext(Config2.class); + assertSame(TestUtils.getPropertyValue(ctx1.getBean(IntegrationMBeanExporter.class), "server"), + TestUtils.getPropertyValue(ctx2.getBean(IntegrationMBeanExporter.class), "server")); + ctx1.close(); + ctx2.close(); + } + + @EnableIntegration + @EnableIntegrationMBeanExport(defaultDomain = "config1") + public static class Config1 { + + } + + @EnableIntegration + @EnableIntegrationMBeanExport(defaultDomain = "config2") + public static class Config2 { + + } + public static class BogusEndpoint extends AbstractEndpoint { @SuppressWarnings("unused")