diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceProperties.java index c0ab1f5b8c..7f0f6e246a 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 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. @@ -44,6 +44,7 @@ import org.springframework.util.StringUtils; * @author Stephane Nicoll * @author Benedikt Ritter * @author Eddú Meléndez + * @author Scott Frederick * @since 1.1.0 */ @ConfigurationProperties(prefix = "spring.datasource") @@ -59,7 +60,7 @@ public class DataSourceProperties implements BeanClassLoaderAware, InitializingB /** * Whether to generate a random datasource name. */ - private boolean generateUniqueName; + private boolean generateUniqueName = true; /** * Fully qualified name of the connection pool implementation to use. By default, it diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourcePropertiesTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourcePropertiesTests.java index 551caea1fa..6f47aecb95 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourcePropertiesTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourcePropertiesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 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. @@ -30,6 +30,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; * @author Maciej Walkowiak * @author Stephane Nicoll * @author Eddú Meléndez + * @author Scott Frederick */ class DataSourcePropertiesTests { @@ -51,8 +52,9 @@ class DataSourcePropertiesTests { } @Test - void determineUrl() throws Exception { + void determineUrlWithoutGenerateUniqueName() throws Exception { DataSourceProperties properties = new DataSourceProperties(); + properties.setGenerateUniqueName(false); properties.afterPropertiesSet(); assertThat(properties.getUrl()).isNull(); assertThat(properties.determineUrl()).isEqualTo(EmbeddedDatabaseConnection.H2.getUrl("testdb")); @@ -79,7 +81,6 @@ class DataSourcePropertiesTests { @Test void determineUrlWithGenerateUniqueName() throws Exception { DataSourceProperties properties = new DataSourceProperties(); - properties.setGenerateUniqueName(true); properties.afterPropertiesSet(); assertThat(properties.determineUrl()).isEqualTo(properties.determineUrl());