diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointMBeanExportAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointMBeanExportAutoConfiguration.java index a47728f777..196c92b5bc 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointMBeanExportAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointMBeanExportAutoConfiguration.java @@ -24,10 +24,12 @@ import org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.jmx.support.MBeanServerFactoryBean; import org.springframework.util.StringUtils; /** @@ -61,4 +63,11 @@ public class EndpointMBeanExportAutoConfiguration { return mbeanExporter; } + @Bean + @ConditionalOnMissingBean(MBeanServer.class) + public MBeanServerFactoryBean mbeanServer() { + MBeanServerFactoryBean factory = new MBeanServerFactoryBean(); + factory.setLocateExistingServerIfPossible(true); + return factory; + } } \ No newline at end of file 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 0030e68636..3caf8b0b1a 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 @@ -16,15 +16,19 @@ package org.springframework.boot.autoconfigure.integration; +import javax.management.MBeanServer; + import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.integration.config.EnableIntegration; import org.springframework.integration.jmx.config.EnableIntegrationMBeanExport; import org.springframework.integration.jmx.config.IntegrationMBeanExportConfiguration; +import org.springframework.jmx.support.MBeanServerFactoryBean; /** * {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration @@ -52,4 +56,12 @@ public class IntegrationAutoConfiguration { protected static class IntegrationJmxConfiguration { } + @Bean + @ConditionalOnMissingBean(MBeanServer.class) + public MBeanServerFactoryBean mbeanServer() { + MBeanServerFactoryBean factory = new MBeanServerFactoryBean(); + factory.setLocateExistingServerIfPossible(true); + return factory; + } + }