This commit is contained in:
Phillip Webb
2016-08-29 20:20:45 +01:00
parent 850141c405
commit 565ad79856
19 changed files with 151 additions and 137 deletions

View File

@@ -24,10 +24,10 @@ import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurerAdapt
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
/**
* A {@code RepositoryRestConfigurer} that applies that applies configuration items
* from the {@code spring.data.rest} namespace to Spring Data REST. Also, if a
* {@link Jackson2ObjectMapperBuilder} is available, it is used to configure Spring
* Data REST's {@link ObjectMapper ObjectMappers}.
* A {@code RepositoryRestConfigurer} that applies that applies configuration items from
* the {@code spring.data.rest} namespace to Spring Data REST. Also, if a
* {@link Jackson2ObjectMapperBuilder} is available, it is used to configure Spring Data
* REST's {@link ObjectMapper ObjectMappers}.
*
* @author Andy Wilkinson
* @author Stephane Nicoll

View File

@@ -101,7 +101,7 @@ public class DataSourceAutoConfiguration {
@ConditionalOnMissingBean({ DataSource.class, XADataSource.class })
@Import({ DataSourceConfiguration.Tomcat.class, DataSourceConfiguration.Hikari.class,
DataSourceConfiguration.Dbcp.class, DataSourceConfiguration.Dbcp2.class,
DataSourceConfiguration.Generic.class})
DataSourceConfiguration.Generic.class })
protected static class PooledDataSourceConfiguration {
}
@@ -139,10 +139,12 @@ public class DataSourceAutoConfiguration {
}
@ConditionalOnProperty(prefix = "spring.datasource", name = "type")
static class ExplicitType { }
static class ExplicitType {
}
@Conditional(PooledDataSourceAvailableCondition.class)
static class PooledDataSourceAvailable { }
static class PooledDataSourceAvailable {
}
}

View File

@@ -114,10 +114,10 @@ abstract class DataSourceConfiguration {
static class Generic {
@Bean
public DataSource dataSource(
DataSourceProperties properties) {
public DataSource dataSource(DataSourceProperties properties) {
return properties.initializeDataSourceBuilder().build();
}
}
}

View File

@@ -166,15 +166,13 @@ public class DataSourceProperties
/**
* Initialize a {@link DataSourceBuilder} with the state of this instance.
* @return a {@link DataSourceBuilder} initialized with the customizations
* defined on this instance
* @return a {@link DataSourceBuilder} initialized with the customizations defined on
* this instance
*/
public DataSourceBuilder initializeDataSourceBuilder() {
return DataSourceBuilder.create(getClassLoader())
.type(getType())
.driverClassName(determineDriverClassName())
.url(determineUrl()).username(determineUsername())
.password(determinePassword());
return DataSourceBuilder.create(getClassLoader()).type(getType())
.driverClassName(determineDriverClassName()).url(determineUrl())
.username(determineUsername()).password(determinePassword());
}
public String getName() {

View File

@@ -22,24 +22,28 @@ import org.springframework.boot.diagnostics.FailureAnalysis;
/**
* An {@link AbstractFailureAnalyzer} that performs analysis of a Hikari configuration
* failure caused by the use of the unsupported 'dataSourceClassName' property.
*
* @author Stephane Nicoll
*/
class HikariDriverConfigurationFailureAnalyzer extends AbstractFailureAnalyzer<IllegalStateException> {
class HikariDriverConfigurationFailureAnalyzer
extends AbstractFailureAnalyzer<IllegalStateException> {
static final String EXPECTED_MESSAGE = "both driverClassName and dataSourceClassName are " +
"specified, one or the other should be used";
private static final String EXPECTED_MESSAGE = "both driverClassName and "
+ "dataSourceClassName are specified, one or the other should be used";
@Override
protected FailureAnalysis analyze(Throwable rootFailure, IllegalStateException cause) {
protected FailureAnalysis analyze(Throwable rootFailure,
IllegalStateException cause) {
if (!EXPECTED_MESSAGE.equals(cause.getMessage())) {
return null;
}
return new FailureAnalysis("Configuration of the Hikari connection pool failed: " +
"'dataSourceClassName' is not supported.",
"Spring Boot auto-configures only a driver and can't specify a custom " +
"DataSource. Consider configuring the Hikari DataSource in your " +
"own configuration.", cause);
return new FailureAnalysis(
"Configuration of the Hikari connection pool failed: "
+ "'dataSourceClassName' is not supported.",
"Spring Boot auto-configures only a driver and can't specify a custom "
+ "DataSource. Consider configuring the Hikari DataSource in "
+ "your own configuration.",
cause);
}
}

View File

@@ -186,8 +186,8 @@ public class DataSourceAutoConfigurationTests {
}
/**
* This test makes sure that if no supported data source is present, a datasource
* is still created if "spring.datasource.type" is present.
* This test makes sure that if no supported data source is present, a datasource is
* still created if "spring.datasource.type" is present.
*/
@Test
public void explicitTypeNoSupportedDataSource() {
@@ -195,9 +195,9 @@ public class DataSourceAutoConfigurationTests {
"spring.datasource.driverClassName:org.hsqldb.jdbcDriver",
"spring.datasource.url:jdbc:hsqldb:mem:testdb",
"spring.datasource.type:" + SimpleDriverDataSource.class.getName());
this.context.setClassLoader(new HidePackagesClassLoader(
"org.apache.tomcat", "com.zaxxer.hikari", "org.apache.commons.dbcp",
"org.apache.commons.dbcp2"));
this.context.setClassLoader(
new HidePackagesClassLoader("org.apache.tomcat", "com.zaxxer.hikari",
"org.apache.commons.dbcp", "org.apache.commons.dbcp2"));
testExplicitType();
}
@@ -329,7 +329,6 @@ public class DataSourceAutoConfigurationTests {
this.hiddenPackages = hiddenPackages;
}
@Override
protected Class<?> loadClass(String name, boolean resolve)
throws ClassNotFoundException {

View File

@@ -39,11 +39,11 @@ public class HikariDriverConfigurationFailureAnalyzerTests {
public void failureAnalysisIsPerformed() {
FailureAnalysis failureAnalysis = performAnalysis(TestConfiguration.class);
assertThat(failureAnalysis).isNotNull();
assertThat(failureAnalysis.getDescription()).isEqualTo(
"Configuration of the Hikari connection pool failed: " +
"'dataSourceClassName' is not supported.");
assertThat(failureAnalysis.getAction()).contains(
"Spring Boot auto-configures only a driver");
assertThat(failureAnalysis.getDescription())
.isEqualTo("Configuration of the Hikari connection pool failed: "
+ "'dataSourceClassName' is not supported.");
assertThat(failureAnalysis.getAction())
.contains("Spring Boot auto-configures only a driver");
}
@Test