diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfiguration.java index 947c717fa3..1ed6ca4899 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfiguration.java @@ -36,13 +36,13 @@ import org.springframework.jmx.export.MBeanExporter; * * @author Stephane Nicoll * @author Andy Wilkinson - * @author Nguyen Bao Sach * @since 1.3.0 * @see SpringApplicationAdminMXBean */ @Configuration(proxyBeanMethods = false) @AutoConfigureAfter(JmxAutoConfiguration.class) -@ConditionalOnProperty(prefix = "spring.application.admin", value = "enabled", havingValue = "true") +@ConditionalOnProperty(prefix = "spring.application.admin", value = "enabled", havingValue = "true", + matchIfMissing = false) public class SpringApplicationAdminJmxAutoConfiguration { /** @@ -61,8 +61,11 @@ public class SpringApplicationAdminJmxAutoConfiguration { public SpringApplicationAdminMXBeanRegistrar springApplicationAdminRegistrar( ObjectProvider mbeanExporters, Environment environment) throws MalformedObjectNameException { String jmxName = environment.getProperty(JMX_NAME_PROPERTY, DEFAULT_JMX_NAME); - // Make sure to not register that MBean twice - mbeanExporters.forEach((mbeanExporter) -> mbeanExporter.addExcludedBean(jmxName)); + if (mbeanExporters != null) { // Make sure to not register that MBean twice + for (MBeanExporter mbeanExporter : mbeanExporters) { + mbeanExporter.addExcludedBean(jmxName); + } + } return new SpringApplicationAdminMXBeanRegistrar(jmxName); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfigurationTests.java index 9c80ecec8d..389ec27b0a 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 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. @@ -64,7 +64,7 @@ class SpringApplicationAdminJmxAutoConfigurationTests { .withConfiguration(AutoConfigurations.of(SpringApplicationAdminJmxAutoConfiguration.class)); @Test - void WhenThereAreNotAnyMBeanExporters() { + void notRegisteredWhenThereAreNoMBeanExporter() { this.contextRunner.withPropertyValues(ENABLE_ADMIN_PROP).run((context) -> { ObjectName objectName = createDefaultObjectName(); ObjectInstance objectInstance = this.server.getObjectInstance(objectName);