Skip to content

Commit b3517a0

Browse files
committed
Merge branch '2.2.x'
Closes gh-20671
2 parents ffe12f0 + 009361d commit b3517a0

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}.
@@ -119,14 +118,16 @@ public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeM
119118
*/
120119
static class EmbeddedDatabaseCondition extends SpringBootCondition {
121120

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

124125
@Override
125126
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
126127
ConditionMessage.Builder message = ConditionMessage.forCondition("EmbeddedDataSource");
127-
String url = context.getEnvironment().getProperty("spring.datasource.url");
128-
if (StringUtils.hasText(url)) {
129-
return ConditionOutcome.noMatch(message.found("explicit url").items(url));
128+
boolean hasDatasourceUrl = context.getEnvironment().containsProperty(DATASOURCE_URL_PROPERTY);
129+
if (hasDatasourceUrl) {
130+
return ConditionOutcome.noMatch(message.because(DATASOURCE_URL_PROPERTY + " is set"));
130131
}
131132
if (anyMatches(context, metadata, this.pooledCondition)) {
132133
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
@@ -202,6 +202,13 @@ void testDefaultDataSourceCanBeOverridden() {
202202
.run((context) -> assertThat(context).getBean(DataSource.class).isInstanceOf(BasicDataSource.class));
203203
}
204204

205+
@Test
206+
void whenThereIsAUserProvidedDataSourceAnUnresolvablePlaceholderDoesNotCauseAProblem() {
207+
this.contextRunner.withUserConfiguration(TestDataSourceConfiguration.class)
208+
.withPropertyValues("spring.datasource.url:${UNRESOLVABLE_PLACEHOLDER}")
209+
.run((context) -> assertThat(context).getBean(DataSource.class).isInstanceOf(BasicDataSource.class));
210+
}
211+
205212
@Test
206213
void testDataSourceIsInitializedEarly() {
207214
this.contextRunner.withUserConfiguration(TestInitializedDataSourceConfiguration.class)

0 commit comments

Comments
 (0)