diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/JmxEndpointIntegrationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/JmxEndpointIntegrationTests.java index d81cda55212..1c3d9775cdb 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/JmxEndpointIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/JmxEndpointIntegrationTests.java @@ -50,7 +50,7 @@ public class JmxEndpointIntegrationTests { EndpointAutoConfiguration.class, JmxEndpointAutoConfiguration.class, HealthIndicatorAutoConfiguration.class, HttpTraceAutoConfiguration.class)) - .withConfiguration( + .withPropertyValues("spring.jmx.enabled=true").withConfiguration( AutoConfigurations.of(EndpointAutoConfigurationClasses.ALL)); @Test diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/KafkaMetricsAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/KafkaMetricsAutoConfigurationTests.java index 227eb3cb1aa..3fe74427dc2 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/KafkaMetricsAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/KafkaMetricsAutoConfigurationTests.java @@ -36,7 +36,8 @@ import static org.assertj.core.api.Assertions.assertThat; public class KafkaMetricsAutoConfigurationTests { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .with(MetricsRun.simple()).withConfiguration( + .with(MetricsRun.simple()).withPropertyValues("spring.jmx.enabled=true") + .withConfiguration( AutoConfigurations.of(KafkaMetricsAutoConfiguration.class)); @Test diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jmx/JmxAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jmx/JmxAutoConfiguration.java index 3f297b3b44d..1de92f0bc30 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jmx/JmxAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jmx/JmxAutoConfiguration.java @@ -42,7 +42,7 @@ import org.springframework.util.StringUtils; * {@link EnableAutoConfiguration Auto-configuration} to enable/disable Spring's * {@link EnableMBeanExport} mechanism based on configuration properties. *
- * To disable auto export of annotation beans set {@code spring.jmx.enabled: false}. + * To enable auto export of annotation beans set {@code spring.jmx.enabled: true}. * * @author Christian Dupuis * @author Madhura Bhave @@ -50,7 +50,7 @@ import org.springframework.util.StringUtils; */ @Configuration @ConditionalOnClass({ MBeanExporter.class }) -@ConditionalOnProperty(prefix = "spring.jmx", name = "enabled", havingValue = "true", matchIfMissing = true) +@ConditionalOnProperty(prefix = "spring.jmx", name = "enabled", havingValue = "true") public class JmxAutoConfiguration { private final Environment environment; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 5a4d2130777..19f06f3c521 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -463,7 +463,7 @@ "name": "spring.jmx.enabled", "type": "java.lang.Boolean", "description": "Expose management beans to the JMX domain.", - "defaultValue": true + "defaultValue": false }, { "name": "spring.jmx.server", diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java index aed522e92a0..f42edc72c50 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -101,31 +101,30 @@ public class IntegrationAutoConfigurationTests { } @Test - public void jmxIntegrationEnabledByDefault() { - this.contextRunner.run((context) -> { - MBeanServer mBeanServer = context.getBean(MBeanServer.class); - assertThat(mBeanServer.getDomains()).contains( - "org.springframework.integration", - "org.springframework.integration.monitor"); - assertThat(context) - .hasBean(IntegrationManagementConfigurer.MANAGEMENT_CONFIGURER_NAME); - }); - } - - @Test - public void disableJmxIntegration() { - this.contextRunner.withPropertyValues("spring.jmx.enabled=false") + public void enableJmxIntegration() { + this.contextRunner.withPropertyValues("spring.jmx.enabled=true") .run((context) -> { - assertThat(context).doesNotHaveBean(MBeanServer.class); - assertThat(context) - .hasSingleBean(IntegrationManagementConfigurer.class); + MBeanServer mBeanServer = context.getBean(MBeanServer.class); + assertThat(mBeanServer.getDomains()).contains( + "org.springframework.integration", + "org.springframework.integration.monitor"); + assertThat(context).hasBean( + IntegrationManagementConfigurer.MANAGEMENT_CONFIGURER_NAME); }); } + @Test + public void jmxIntegrationIsDisabledByDefault() { + this.contextRunner.run((context) -> { + assertThat(context).doesNotHaveBean(MBeanServer.class); + assertThat(context).hasSingleBean(IntegrationManagementConfigurer.class); + }); + } + @Test public void customizeJmxDomain() { - this.contextRunner.withPropertyValues("spring.jmx.default_domain=org.foo") - .run((context) -> { + this.contextRunner.withPropertyValues("spring.jmx.enabled=true", + "spring.jmx.default_domain=org.foo").run((context) -> { MBeanServer mBeanServer = context.getBean(MBeanServer.class); assertThat(mBeanServer.getDomains()).contains("org.foo") .doesNotContain("org.springframework.integration", @@ -135,8 +134,8 @@ public class IntegrationAutoConfigurationTests { @Test public void primaryExporterIsAllowed() { - this.contextRunner.withUserConfiguration(CustomMBeanExporter.class) - .run((context) -> { + this.contextRunner.withPropertyValues("spring.jmx.enabled=true") + .withUserConfiguration(CustomMBeanExporter.class).run((context) -> { assertThat(context).getBeans(MBeanExporter.class).hasSize(2); assertThat(context.getBean(MBeanExporter.class)) .isSameAs(context.getBean("myMBeanExporter")); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceJmxConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceJmxConfigurationTests.java index 38e5870abca..ca0952a8cfd 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceJmxConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceJmxConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -60,7 +60,7 @@ public class DataSourceJmxConfigurationTests { public void hikariAutoConfiguredCanUseRegisterMBeans() { String poolName = UUID.randomUUID().toString(); this.contextRunner - .withPropertyValues( + .withPropertyValues("spring.jmx.enabled=true", "spring.datasource.type=" + HikariDataSource.class.getName(), "spring.datasource.name=" + poolName, "spring.datasource.hikari.register-mbeans=true") @@ -118,7 +118,7 @@ public class DataSourceJmxConfigurationTests { public void hikariProxiedCanUseRegisterMBeans() { String poolName = UUID.randomUUID().toString(); this.contextRunner.withUserConfiguration(DataSourceProxyConfiguration.class) - .withPropertyValues( + .withPropertyValues("spring.jmx.enabled=true", "spring.datasource.type=" + HikariDataSource.class.getName(), "spring.datasource.name=" + poolName, "spring.datasource.hikari.register-mbeans=true") diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jmx/JmxAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jmx/JmxAutoConfigurationTests.java index f1308f68b75..61c7ba9ce24 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jmx/JmxAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jmx/JmxAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -63,7 +63,8 @@ public class JmxAutoConfigurationTests { this.context = new AnnotationConfigApplicationContext(); this.context.register(JmxAutoConfiguration.class); this.context.refresh(); - assertThat(this.context.getBean(MBeanExporter.class)).isNotNull(); + assertThatExceptionOfType(NoSuchBeanDefinitionException.class) + .isThrownBy(() -> this.context.getBean(MBeanExporter.class)); } @Test diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc index 26dd7cce2ff..5d9e7f736d4 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc @@ -1217,8 +1217,9 @@ following example: [[production-ready-jmx]] == Monitoring and Management over JMX Java Management Extensions (JMX) provide a standard mechanism to monitor and manage -applications. By default, Spring Boot exposes management endpoints as JMX MBeans under -the `org.springframework.boot` domain. +applications. By default, this feature is not enabled and can be turned on with +the configuration property `spring.jmx.enabled=true`. Spring Boot exposes +management endpoints as JMX MBeans under the `org.springframework.boot` domain by default.