commit
009361d38c
|
|
@ -38,7 +38,6 @@ import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.core.type.AnnotatedTypeMetadata;
|
import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link EnableAutoConfiguration Auto-configuration} for {@link DataSource}.
|
* {@link EnableAutoConfiguration Auto-configuration} for {@link DataSource}.
|
||||||
|
|
@ -118,14 +117,16 @@ public class DataSourceAutoConfiguration {
|
||||||
*/
|
*/
|
||||||
static class EmbeddedDatabaseCondition extends SpringBootCondition {
|
static class EmbeddedDatabaseCondition extends SpringBootCondition {
|
||||||
|
|
||||||
|
private static final String DATASOURCE_URL_PROPERTY = "spring.datasource.url";
|
||||||
|
|
||||||
private final SpringBootCondition pooledCondition = new PooledDataSourceCondition();
|
private final SpringBootCondition pooledCondition = new PooledDataSourceCondition();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
|
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
|
||||||
ConditionMessage.Builder message = ConditionMessage.forCondition("EmbeddedDataSource");
|
ConditionMessage.Builder message = ConditionMessage.forCondition("EmbeddedDataSource");
|
||||||
String url = context.getEnvironment().getProperty("spring.datasource.url");
|
boolean hasDatasourceUrl = context.getEnvironment().containsProperty(DATASOURCE_URL_PROPERTY);
|
||||||
if (StringUtils.hasText(url)) {
|
if (hasDatasourceUrl) {
|
||||||
return ConditionOutcome.noMatch(message.found("explicit url").items(url));
|
return ConditionOutcome.noMatch(message.because(DATASOURCE_URL_PROPERTY + " is set"));
|
||||||
}
|
}
|
||||||
if (anyMatches(context, metadata, this.pooledCondition)) {
|
if (anyMatches(context, metadata, this.pooledCondition)) {
|
||||||
return ConditionOutcome.noMatch(message.foundExactly("supported pooled data source"));
|
return ConditionOutcome.noMatch(message.foundExactly("supported pooled data source"));
|
||||||
|
|
|
||||||
|
|
@ -194,6 +194,13 @@ class DataSourceAutoConfigurationTests {
|
||||||
.run((context) -> assertThat(context).getBean(DataSource.class).isInstanceOf(BasicDataSource.class));
|
.run((context) -> assertThat(context).getBean(DataSource.class).isInstanceOf(BasicDataSource.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void whenThereIsAUserProvidedDataSourceAnUnresolvablePlaceholderDoesNotCauseAProblem() {
|
||||||
|
this.contextRunner.withUserConfiguration(TestDataSourceConfiguration.class)
|
||||||
|
.withPropertyValues("spring.datasource.url:${UNRESOLVABLE_PLACEHOLDER}")
|
||||||
|
.run((context) -> assertThat(context).getBean(DataSource.class).isInstanceOf(BasicDataSource.class));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testDataSourceIsInitializedEarly() {
|
void testDataSourceIsInitializedEarly() {
|
||||||
this.contextRunner.withUserConfiguration(TestInitializedDataSourceConfiguration.class)
|
this.contextRunner.withUserConfiguration(TestInitializedDataSourceConfiguration.class)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue