Remove `@Primary` from `IntegrationMBeanExporter`

Commit 3ea84f9e1 has wrongly introduced a `@Primary` marker on
`IntegrationMBeanExporter` so any use of both Spring's JMX support
and Spring Integration's JMX support leads to an exception. This commit
makes sure to remove the unnecessary `@Primary`

Closes gh-6328
This commit is contained in:
Stephane Nicoll 2016-07-07 15:36:02 +02:00
parent eeb95693b3
commit bbb29dd70f
2 changed files with 32 additions and 3 deletions

View File

@ -33,7 +33,6 @@ import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.env.Environment;
import org.springframework.integration.config.EnableIntegration;
import org.springframework.integration.jmx.config.EnableIntegrationMBeanExport;
@ -87,7 +86,6 @@ public class IntegrationAutoConfiguration {
}
@Bean
@Primary
public IntegrationMBeanExporter integrationMbeanExporter() {
IntegrationMBeanExporter exporter = new IntegrationMBeanExporter();
String defaultDomain = this.propertyResolver.getProperty("default-domain");

View File

@ -27,11 +27,17 @@ import org.junit.Test;
import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.integration.support.channel.HeaderChannelRegistry;
import org.springframework.jmx.export.MBeanExporter;
import org.springframework.test.context.support.TestPropertySourceUtils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;
/**
* Tests for {@link IntegrationAutoConfiguration}.
@ -99,6 +105,13 @@ public class IntegrationAutoConfigurationTests {
"org.springframework.integration.monitor");
}
@Test
public void primaryExporterIsAllowed() {
load(CustomMBeanExporter.class);
assertEquals(2, this.context.getBeansOfType(MBeanExporter.class).size());
assertSame(this.context.getBean("myMBeanExporter"), this.context.getBean(MBeanExporter.class));
}
private static void assertDomains(MBeanServer mBeanServer, boolean expected,
String... domains) {
List<String> actual = Arrays.asList(mBeanServer.getDomains());
@ -107,12 +120,30 @@ public class IntegrationAutoConfigurationTests {
}
}
private void load(String... environment) {
public void load(String... environment) {
load(null, environment);
}
private void load(Class<?> config, String... environment) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
if (config != null) {
ctx.register(config);
}
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(ctx, environment);
ctx.register(JmxAutoConfiguration.class, IntegrationAutoConfiguration.class);
ctx.refresh();
this.context = ctx;
}
@Configuration
static class CustomMBeanExporter {
@Bean
@Primary
public MBeanExporter myMBeanExporter() {
return mock(MBeanExporter.class);
}
}
}