Merge branch '2.0.x'

pull/13039/head
Stephane Nicoll 7 years ago
commit 921c037956

@ -58,12 +58,12 @@ class DataSourceBeanCreationFailureAnalyzer
private String getDescription(DataSourceBeanCreationException cause) { private String getDescription(DataSourceBeanCreationException cause) {
StringBuilder description = new StringBuilder(); StringBuilder description = new StringBuilder();
description.append("Failed to auto-configure a DataSource: "); description.append("Failed to configure a DataSource: ");
if (!this.environment.containsProperty("spring.datasource.url")) { if (!StringUtils.hasText(cause.getProperties().getUrl())) {
description.append("'spring.datasource.url' is not specified and "); description.append("'url' attribute is not specified and ");
} }
description.append( description.append(
String.format("no embedded datasource could be auto-configured.%n")); String.format("no embedded datasource could be configured.%n"));
description.append(String.format("%nReason: %s%n", cause.getMessage())); description.append(String.format("%nReason: %s%n", cause.getMessage()));
return description.toString(); return description.toString();
} }

@ -235,7 +235,7 @@ public class DataSourceProperties implements BeanClassLoaderAware, InitializingB
if (!StringUtils.hasText(driverClassName)) { if (!StringUtils.hasText(driverClassName)) {
throw new DataSourceBeanCreationException( throw new DataSourceBeanCreationException(
"Failed to determine a suitable driver class", "Failed to determine a suitable driver class",
this.embeddedDatabaseConnection); this, this.embeddedDatabaseConnection);
} }
return driverClassName; return driverClassName;
} }
@ -282,7 +282,7 @@ public class DataSourceProperties implements BeanClassLoaderAware, InitializingB
if (!StringUtils.hasText(url)) { if (!StringUtils.hasText(url)) {
throw new DataSourceBeanCreationException( throw new DataSourceBeanCreationException(
"Failed to determine suitable jdbc url", "Failed to determine suitable jdbc url",
this.embeddedDatabaseConnection); this, this.embeddedDatabaseConnection);
} }
return url; return url;
} }
@ -513,14 +513,21 @@ public class DataSourceProperties implements BeanClassLoaderAware, InitializingB
static class DataSourceBeanCreationException extends BeanCreationException { static class DataSourceBeanCreationException extends BeanCreationException {
private final DataSourceProperties properties;
private final EmbeddedDatabaseConnection connection; private final EmbeddedDatabaseConnection connection;
DataSourceBeanCreationException(String message, DataSourceBeanCreationException(String message, DataSourceProperties properties,
EmbeddedDatabaseConnection connection) { EmbeddedDatabaseConnection connection) {
super(message); super(message);
this.properties = properties;
this.connection = connection; this.connection = connection;
} }
public DataSourceProperties getProperties() {
return this.properties;
}
public EmbeddedDatabaseConnection getConnection() { public EmbeddedDatabaseConnection getConnection() {
return this.connection; return this.connection;
} }

@ -46,8 +46,8 @@ public class DataSourceBeanCreationFailureAnalyzerTests {
public void failureAnalysisIsPerformed() { public void failureAnalysisIsPerformed() {
FailureAnalysis failureAnalysis = performAnalysis(TestConfiguration.class); FailureAnalysis failureAnalysis = performAnalysis(TestConfiguration.class);
assertThat(failureAnalysis.getDescription()).contains( assertThat(failureAnalysis.getDescription()).contains(
"'spring.datasource.url' is not specified", "'url' attribute is not specified",
"no embedded datasource could be auto-configured", "no embedded datasource could be configured",
"Failed to determine a suitable driver class"); "Failed to determine a suitable driver class");
assertThat(failureAnalysis.getAction()).contains( assertThat(failureAnalysis.getAction()).contains(
"If you want an embedded database (H2, HSQL or Derby), please put it on the classpath", "If you want an embedded database (H2, HSQL or Derby), please put it on the classpath",

Loading…
Cancel
Save