From 08bc306a6138d88c954b7333276cef80e721b5db Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 2 May 2018 10:35:17 +0200 Subject: [PATCH] Guard IntegrationJmxConfiguration if no mBeanServer is available Closes gh-12966 --- .../integration/IntegrationAutoConfiguration.java | 4 +++- .../IntegrationAutoConfigurationTests.java | 12 +++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java index 0241676b84..4dae5fe9be 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2018 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,6 +22,7 @@ import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -70,6 +71,7 @@ public class IntegrationAutoConfiguration { @Configuration @ConditionalOnClass(EnableIntegrationMBeanExport.class) @ConditionalOnMissingBean(value = IntegrationMBeanExporter.class, search = SearchStrategy.CURRENT) + @ConditionalOnBean(MBeanServer.class) @ConditionalOnProperty(prefix = "spring.jmx", name = "enabled", havingValue = "true", matchIfMissing = true) protected static class IntegrationJmxConfiguration implements EnvironmentAware, BeanFactoryAware { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java index 381b945f8e..a5880f8a1e 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2018 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. @@ -82,6 +82,16 @@ public class IntegrationAutoConfigurationTests { .isEmpty(); } + @Test + public void noMBeanServerAvailable() { + this.context = new AnnotationConfigApplicationContext(); + this.context.register(IntegrationAutoConfiguration.class); + this.context.refresh(); + assertThat(this.context.getBean(TestGateway.class)).isNotNull(); + assertThat(this.context.getBean(IntegrationComponentScanAutoConfiguration.class)) + .isNotNull(); + } + @Test public void parentContext() { load();