Skip to content

Commit 08bc306

Browse files
committed
Guard IntegrationJmxConfiguration if no mBeanServer is available
Closes spring-projectsgh-12966
1 parent 4585bc8 commit 08bc306

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@
2222
import org.springframework.beans.factory.BeanFactory;
2323
import org.springframework.beans.factory.BeanFactoryAware;
2424
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
25+
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
2526
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2627
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
2728
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@@ -70,6 +71,7 @@ protected static class IntegrationConfiguration {
7071
@Configuration
7172
@ConditionalOnClass(EnableIntegrationMBeanExport.class)
7273
@ConditionalOnMissingBean(value = IntegrationMBeanExporter.class, search = SearchStrategy.CURRENT)
74+
@ConditionalOnBean(MBeanServer.class)
7375
@ConditionalOnProperty(prefix = "spring.jmx", name = "enabled", havingValue = "true", matchIfMissing = true)
7476
protected static class IntegrationJmxConfiguration
7577
implements EnvironmentAware, BeanFactoryAware {

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -82,6 +82,16 @@ public void explicitIntegrationComponentScan() {
8282
.isEmpty();
8383
}
8484

85+
@Test
86+
public void noMBeanServerAvailable() {
87+
this.context = new AnnotationConfigApplicationContext();
88+
this.context.register(IntegrationAutoConfiguration.class);
89+
this.context.refresh();
90+
assertThat(this.context.getBean(TestGateway.class)).isNotNull();
91+
assertThat(this.context.getBean(IntegrationComponentScanAutoConfiguration.class))
92+
.isNotNull();
93+
}
94+
8595
@Test
8696
public void parentContext() {
8797
load();

0 commit comments

Comments
 (0)