Guard IntegrationJmxConfiguration if no mBeanServer is available

Closes gh-12966
This commit is contained in:
Stephane Nicoll 2018-05-02 10:35:17 +02:00
parent 4585bc846a
commit 08bc306a61
2 changed files with 14 additions and 2 deletions

View File

@ -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 {

View File

@ -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();