Skip to content

Commit 009361d

Browse files
committed
Merge branch '2.1.x' into 2.2.x
Closes gh-20670
2 parents 089c047 + 1835323 commit 009361d

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import org.springframework.context.annotation.Import;
3939
import org.springframework.core.type.AnnotatedTypeMetadata;
4040
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
41-
import org.springframework.util.StringUtils;
4241

4342
/**
4443
* {@link EnableAutoConfiguration Auto-configuration} for {@link DataSource}.
@@ -118,14 +117,16 @@ public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeM
118117
*/
119118
static class EmbeddedDatabaseCondition extends SpringBootCondition {
120119

120+
private static final String DATASOURCE_URL_PROPERTY = "spring.datasource.url";
121+
121122
private final SpringBootCondition pooledCondition = new PooledDataSourceCondition();
122123

123124
@Override
124125
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
125126
ConditionMessage.Builder message = ConditionMessage.forCondition("EmbeddedDataSource");
126-
String url = context.getEnvironment().getProperty("spring.datasource.url");
127-
if (StringUtils.hasText(url)) {
128-
return ConditionOutcome.noMatch(message.found("explicit url").items(url));
127+
boolean hasDatasourceUrl = context.getEnvironment().containsProperty(DATASOURCE_URL_PROPERTY);
128+
if (hasDatasourceUrl) {
129+
return ConditionOutcome.noMatch(message.because(DATASOURCE_URL_PROPERTY + " is set"));
129130
}
130131
if (anyMatches(context, metadata, this.pooledCondition)) {
131132
return ConditionOutcome.noMatch(message.foundExactly("supported pooled data source"));

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,13 @@ void testDefaultDataSourceCanBeOverridden() {
194194
.run((context) -> assertThat(context).getBean(DataSource.class).isInstanceOf(BasicDataSource.class));
195195
}
196196

197+
@Test
198+
void whenThereIsAUserProvidedDataSourceAnUnresolvablePlaceholderDoesNotCauseAProblem() {
199+
this.contextRunner.withUserConfiguration(TestDataSourceConfiguration.class)
200+
.withPropertyValues("spring.datasource.url:${UNRESOLVABLE_PLACEHOLDER}")
201+
.run((context) -> assertThat(context).getBean(DataSource.class).isInstanceOf(BasicDataSource.class));
202+
}
203+
197204
@Test
198205
void testDataSourceIsInitializedEarly() {
199206
this.contextRunner.withUserConfiguration(TestInitializedDataSourceConfiguration.class)

0 commit comments

Comments
 (0)