Disable JMX by default

This commit switches the default value for the `spring.jmx.enabled`
configuration property.
JMX is now disabled by default and can be enabled with
`spring.jmx.enabled=true`.

Closes gh-16090
This commit is contained in:
Brian Clozel 2019-03-05 15:30:19 +01:00
parent d403dae6fc
commit ce9626d00f
8 changed files with 36 additions and 34 deletions

View File

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

View File

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

View File

@ -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.
* <p>
* 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;

View File

@ -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",

View File

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

View File

@ -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")

View File

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

View File

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