Skip to content

Commit bbb29dd

Browse files
committed
Remove @Primary from IntegrationMBeanExporter
Commit 3ea84f9 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
1 parent eeb9569 commit bbb29dd

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import org.springframework.context.EnvironmentAware;
3434
import org.springframework.context.annotation.Bean;
3535
import org.springframework.context.annotation.Configuration;
36-
import org.springframework.context.annotation.Primary;
3736
import org.springframework.core.env.Environment;
3837
import org.springframework.integration.config.EnableIntegration;
3938
import org.springframework.integration.jmx.config.EnableIntegrationMBeanExport;
@@ -87,7 +86,6 @@ public void setEnvironment(Environment environment) {
8786
}
8887

8988
@Bean
90-
@Primary
9189
public IntegrationMBeanExporter integrationMbeanExporter() {
9290
IntegrationMBeanExporter exporter = new IntegrationMBeanExporter();
9391
String defaultDomain = this.propertyResolver.getProperty("default-domain");

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,17 @@
2727
import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
2828
import org.springframework.context.ConfigurableApplicationContext;
2929
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
30+
import org.springframework.context.annotation.Bean;
31+
import org.springframework.context.annotation.Configuration;
32+
import org.springframework.context.annotation.Primary;
3033
import org.springframework.integration.support.channel.HeaderChannelRegistry;
34+
import org.springframework.jmx.export.MBeanExporter;
3135
import org.springframework.test.context.support.TestPropertySourceUtils;
3236

3337
import static org.junit.Assert.assertEquals;
3438
import static org.junit.Assert.assertNotNull;
39+
import static org.junit.Assert.assertSame;
40+
import static org.mockito.Mockito.mock;
3541

3642
/**
3743
* Tests for {@link IntegrationAutoConfiguration}.
@@ -99,6 +105,13 @@ public void customizeJmxDomain() {
99105
"org.springframework.integration.monitor");
100106
}
101107

108+
@Test
109+
public void primaryExporterIsAllowed() {
110+
load(CustomMBeanExporter.class);
111+
assertEquals(2, this.context.getBeansOfType(MBeanExporter.class).size());
112+
assertSame(this.context.getBean("myMBeanExporter"), this.context.getBean(MBeanExporter.class));
113+
}
114+
102115
private static void assertDomains(MBeanServer mBeanServer, boolean expected,
103116
String... domains) {
104117
List<String> actual = Arrays.asList(mBeanServer.getDomains());
@@ -107,12 +120,30 @@ private static void assertDomains(MBeanServer mBeanServer, boolean expected,
107120
}
108121
}
109122

110-
private void load(String... environment) {
123+
public void load(String... environment) {
124+
load(null, environment);
125+
}
126+
127+
private void load(Class<?> config, String... environment) {
111128
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
129+
if (config != null) {
130+
ctx.register(config);
131+
}
112132
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(ctx, environment);
113133
ctx.register(JmxAutoConfiguration.class, IntegrationAutoConfiguration.class);
114134
ctx.refresh();
115135
this.context = ctx;
116136
}
117137

138+
@Configuration
139+
static class CustomMBeanExporter {
140+
141+
@Bean
142+
@Primary
143+
public MBeanExporter myMBeanExporter() {
144+
return mock(MBeanExporter.class);
145+
}
146+
147+
}
148+
118149
}

0 commit comments

Comments
 (0)