Skip to content

Commit

Permalink
Disable JMX by default
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bclozel committed Mar 5, 2019
1 parent d403dae commit ce9626d
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@
* {@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
* @author Artsiom Yudovin
*/
@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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -101,31 +101,30 @@ public void parentContext() {
}

@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);
});
public void enableJmxIntegration() {
this.contextRunner.withPropertyValues("spring.jmx.enabled=true")
.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")
.run((context) -> {
assertThat(context).doesNotHaveBean(MBeanServer.class);
assertThat(context)
.hasSingleBean(IntegrationManagementConfigurer.class);
});
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",
Expand All @@ -135,8 +134,8 @@ public void customizeJmxDomain() {

@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"));
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -118,7 +118,7 @@ public void hikariAutoConfiguredUsesJmsFlag() {
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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -63,7 +63,8 @@ public void testDefaultMBeanExport() {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.



Expand Down

0 comments on commit ce9626d

Please sign in to comment.