Skip to content

Commit ce9626d

Browse files
committed
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
1 parent d403dae commit ce9626d

File tree

8 files changed

+35
-33
lines changed

8 files changed

+35
-33
lines changed

Diff for: spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/JmxEndpointIntegrationTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class JmxEndpointIntegrationTests {
5050
EndpointAutoConfiguration.class, JmxEndpointAutoConfiguration.class,
5151
HealthIndicatorAutoConfiguration.class,
5252
HttpTraceAutoConfiguration.class))
53-
.withConfiguration(
53+
.withPropertyValues("spring.jmx.enabled=true").withConfiguration(
5454
AutoConfigurations.of(EndpointAutoConfigurationClasses.ALL));
5555

5656
@Test

Diff for: spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/KafkaMetricsAutoConfigurationTests.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
public class KafkaMetricsAutoConfigurationTests {
3737

3838
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
39-
.with(MetricsRun.simple()).withConfiguration(
39+
.with(MetricsRun.simple()).withPropertyValues("spring.jmx.enabled=true")
40+
.withConfiguration(
4041
AutoConfigurations.of(KafkaMetricsAutoConfiguration.class));
4142

4243
@Test

Diff for: spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jmx/JmxAutoConfiguration.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@
4242
* {@link EnableAutoConfiguration Auto-configuration} to enable/disable Spring's
4343
* {@link EnableMBeanExport} mechanism based on configuration properties.
4444
* <p>
45-
* To disable auto export of annotation beans set {@code spring.jmx.enabled: false}.
45+
* To enable auto export of annotation beans set {@code spring.jmx.enabled: true}.
4646
*
4747
* @author Christian Dupuis
4848
* @author Madhura Bhave
4949
* @author Artsiom Yudovin
5050
*/
5151
@Configuration
5252
@ConditionalOnClass({ MBeanExporter.class })
53-
@ConditionalOnProperty(prefix = "spring.jmx", name = "enabled", havingValue = "true", matchIfMissing = true)
53+
@ConditionalOnProperty(prefix = "spring.jmx", name = "enabled", havingValue = "true")
5454
public class JmxAutoConfiguration {
5555

5656
private final Environment environment;

Diff for: spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@
463463
"name": "spring.jmx.enabled",
464464
"type": "java.lang.Boolean",
465465
"description": "Expose management beans to the JMX domain.",
466-
"defaultValue": true
466+
"defaultValue": false
467467
},
468468
{
469469
"name": "spring.jmx.server",

Diff for: spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java

+20-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -101,31 +101,30 @@ public void parentContext() {
101101
}
102102

103103
@Test
104-
public void jmxIntegrationEnabledByDefault() {
105-
this.contextRunner.run((context) -> {
106-
MBeanServer mBeanServer = context.getBean(MBeanServer.class);
107-
assertThat(mBeanServer.getDomains()).contains(
108-
"org.springframework.integration",
109-
"org.springframework.integration.monitor");
110-
assertThat(context)
111-
.hasBean(IntegrationManagementConfigurer.MANAGEMENT_CONFIGURER_NAME);
112-
});
104+
public void enableJmxIntegration() {
105+
this.contextRunner.withPropertyValues("spring.jmx.enabled=true")
106+
.run((context) -> {
107+
MBeanServer mBeanServer = context.getBean(MBeanServer.class);
108+
assertThat(mBeanServer.getDomains()).contains(
109+
"org.springframework.integration",
110+
"org.springframework.integration.monitor");
111+
assertThat(context).hasBean(
112+
IntegrationManagementConfigurer.MANAGEMENT_CONFIGURER_NAME);
113+
});
113114
}
114115

115116
@Test
116-
public void disableJmxIntegration() {
117-
this.contextRunner.withPropertyValues("spring.jmx.enabled=false")
118-
.run((context) -> {
119-
assertThat(context).doesNotHaveBean(MBeanServer.class);
120-
assertThat(context)
121-
.hasSingleBean(IntegrationManagementConfigurer.class);
122-
});
117+
public void jmxIntegrationIsDisabledByDefault() {
118+
this.contextRunner.run((context) -> {
119+
assertThat(context).doesNotHaveBean(MBeanServer.class);
120+
assertThat(context).hasSingleBean(IntegrationManagementConfigurer.class);
121+
});
123122
}
124123

125124
@Test
126125
public void customizeJmxDomain() {
127-
this.contextRunner.withPropertyValues("spring.jmx.default_domain=org.foo")
128-
.run((context) -> {
126+
this.contextRunner.withPropertyValues("spring.jmx.enabled=true",
127+
"spring.jmx.default_domain=org.foo").run((context) -> {
129128
MBeanServer mBeanServer = context.getBean(MBeanServer.class);
130129
assertThat(mBeanServer.getDomains()).contains("org.foo")
131130
.doesNotContain("org.springframework.integration",
@@ -135,8 +134,8 @@ public void customizeJmxDomain() {
135134

136135
@Test
137136
public void primaryExporterIsAllowed() {
138-
this.contextRunner.withUserConfiguration(CustomMBeanExporter.class)
139-
.run((context) -> {
137+
this.contextRunner.withPropertyValues("spring.jmx.enabled=true")
138+
.withUserConfiguration(CustomMBeanExporter.class).run((context) -> {
140139
assertThat(context).getBeans(MBeanExporter.class).hasSize(2);
141140
assertThat(context.getBean(MBeanExporter.class))
142141
.isSameAs(context.getBean("myMBeanExporter"));

Diff for: spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceJmxConfigurationTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -60,7 +60,7 @@ public class DataSourceJmxConfigurationTests {
6060
public void hikariAutoConfiguredCanUseRegisterMBeans() {
6161
String poolName = UUID.randomUUID().toString();
6262
this.contextRunner
63-
.withPropertyValues(
63+
.withPropertyValues("spring.jmx.enabled=true",
6464
"spring.datasource.type=" + HikariDataSource.class.getName(),
6565
"spring.datasource.name=" + poolName,
6666
"spring.datasource.hikari.register-mbeans=true")
@@ -118,7 +118,7 @@ public void hikariAutoConfiguredUsesJmsFlag() {
118118
public void hikariProxiedCanUseRegisterMBeans() {
119119
String poolName = UUID.randomUUID().toString();
120120
this.contextRunner.withUserConfiguration(DataSourceProxyConfiguration.class)
121-
.withPropertyValues(
121+
.withPropertyValues("spring.jmx.enabled=true",
122122
"spring.datasource.type=" + HikariDataSource.class.getName(),
123123
"spring.datasource.name=" + poolName,
124124
"spring.datasource.hikari.register-mbeans=true")

Diff for: spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jmx/JmxAutoConfigurationTests.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -63,7 +63,8 @@ public void testDefaultMBeanExport() {
6363
this.context = new AnnotationConfigApplicationContext();
6464
this.context.register(JmxAutoConfiguration.class);
6565
this.context.refresh();
66-
assertThat(this.context.getBean(MBeanExporter.class)).isNotNull();
66+
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
67+
.isThrownBy(() -> this.context.getBean(MBeanExporter.class));
6768
}
6869

6970
@Test

Diff for: spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc

+3-2
Original file line numberDiff line numberDiff line change
@@ -1217,8 +1217,9 @@ following example:
12171217
[[production-ready-jmx]]
12181218
== Monitoring and Management over JMX
12191219
Java Management Extensions (JMX) provide a standard mechanism to monitor and manage
1220-
applications. By default, Spring Boot exposes management endpoints as JMX MBeans under
1221-
the `org.springframework.boot` domain.
1220+
applications. By default, this feature is not enabled and can be turned on with
1221+
the configuration property `spring.jmx.enabled=true`. Spring Boot exposes
1222+
management endpoints as JMX MBeans under the `org.springframework.boot` domain by default.
12221223

12231224

12241225

0 commit comments

Comments
 (0)