From 96a031cf20bf8bb2ea47edf6e60503003fe5f3a7 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 6 Nov 2014 20:55:04 -0800 Subject: [PATCH] Default spring.datasource.jmx-enabled to false Change the default value of spring.datasource.jmx-enabled to false to prevent InstanceAlreadyExistsException problems when using the Spring Test Framework. Fixes gh-1590 --- .../boot/autoconfigure/jdbc/DataSourceAutoConfiguration.java | 2 +- .../META-INF/additional-spring-configuration-metadata.json | 2 +- .../autoconfigure/jdbc/TomcatDataSourceConfigurationTests.java | 2 ++ .../src/main/asciidoc/appendix-application-properties.adoc | 2 +- .../java/sample/data/jpa/SampleDataJpaApplicationTests.java | 3 ++- .../org/springframework/boot/logging/logback/base.xml | 1 + 6 files changed, 8 insertions(+), 4 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration.java index 6bf2d7b67de..f210942932a 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration.java @@ -145,7 +145,7 @@ public class DataSourceAutoConfiguration { } @Configuration - @ConditionalOnProperty(prefix = "spring.datasource", name = "jmx-enabled", havingValue = "true", matchIfMissing = true) + @ConditionalOnProperty(prefix = "spring.datasource", name = "jmx-enabled") @ConditionalOnClass(name = "org.apache.tomcat.jdbc.pool.DataSourceProxy") @Conditional(DataSourceAutoConfiguration.DataSourceAvailableCondition.class) @ConditionalOnMissingBean(name = "dataSourceMBean") diff --git a/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 23127ac9535..da9f04f2792 100644 --- a/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -27,7 +27,7 @@ "name": "spring.datasource.jmx-enabled", "dataType": "java.lang.Boolean", "description": "Enables JMX support (if provided by the underlying pool).", - "defaultValue": true + "defaultValue": false }, { "name": "spring.data.elasticsearch.repositories.enabled", diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/TomcatDataSourceConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/TomcatDataSourceConfigurationTests.java index 8ee675dd096..6a69224f3a5 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/TomcatDataSourceConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/TomcatDataSourceConfigurationTests.java @@ -32,6 +32,7 @@ import org.springframework.boot.test.EnvironmentTestUtils; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.EnableMBeanExport; import org.springframework.context.annotation.Import; import org.springframework.util.ReflectionUtils; @@ -133,6 +134,7 @@ public class TomcatDataSourceConfigurationTests { @Configuration @Import(DataSourceAutoConfiguration.class) + @EnableMBeanExport protected static class TomcatDataSourceConfiguration { @Autowired diff --git a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index 7f0c34cadbf..a2315d96f2b 100644 --- a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -203,7 +203,7 @@ content into your application; rather pick only the properties that you need. spring.datasource.time-between-eviction-runs-millis= spring.datasource.min-evictable-idle-time-millis= spring.datasource.max-wait= - spring.datasource.jmx-enabled=true # Export JMX MBeans (if supported) + spring.datasource.jmx-enabled=false # Export JMX MBeans (if supported) # DATASOURCE ({sc-spring-boot-autoconfigure}/dao/PersistenceExceptionTranslationAutoConfiguration.{sc-ext}[PersistenceExceptionTranslationAutoConfiguration] spring.dao.exceptiontranslation.enabled=true diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/SampleDataJpaApplicationTests.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/SampleDataJpaApplicationTests.java index 52d53494df5..74f5c237b5a 100644 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/SampleDataJpaApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/SampleDataJpaApplicationTests.java @@ -32,7 +32,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @SpringApplicationConfiguration(classes = SampleDataJpaApplication.class) @WebAppConfiguration // Enable JMX so we can test the MBeans (you can't do this in a properties file) -@TestPropertySource(properties = "spring.jmx.enabled:true") +@TestPropertySource(properties = { "spring.jmx.enabled:true", + "spring.datasource.jmx-enabled:true" }) @ActiveProfiles("scratch") // Separate profile for web tests to avoid clashing databases public class SampleDataJpaApplicationTests { diff --git a/spring-boot/src/main/resources/org/springframework/boot/logging/logback/base.xml b/spring-boot/src/main/resources/org/springframework/boot/logging/logback/base.xml index 0ba7cad843e..c1d00ace848 100644 --- a/spring-boot/src/main/resources/org/springframework/boot/logging/logback/base.xml +++ b/spring-boot/src/main/resources/org/springframework/boot/logging/logback/base.xml @@ -6,6 +6,7 @@ Base logback configuration provided for compatibility with Spring Boot 1.1 +