When compare v2.2.5.RELEASE...v2.2.6.RELEASE/diff-DataSourceAutoConfiguration#EmbeddedDatabaseCondition:
v2.2.5.RELEASE:
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
ConditionMessage.Builder message = ConditionMessage.forCondition("EmbeddedDataSource");
String url = context.getEnvironment().getProperty("spring.datasource.url");
if (StringUtils.hasText(url)) {
return ConditionOutcome.noMatch(message.found("explicit url").items(url));
}
...
}
v2.2.6.RELEASE:
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
ConditionMessage.Builder message = ConditionMessage.forCondition("EmbeddedDataSource");
boolean hasDatasourceUrl = context.getEnvironment().containsProperty(DATASOURCE_URL_PROPERTY);
if (hasDatasourceUrl) {
return ConditionOutcome.noMatch(message.because(DATASOURCE_URL_PROPERTY + " is set"));
}
...
}
In my yaml config file:
spring.datasource:
url: @db.url@
username: @db.username@
password: @db.password@
@db.xxx@
is config by maven property in diferent profile. When use embedded database h2, I set db.url=~
to avoid setting this peoperty. And this setting, `context.getEnvironment() also contain the key "spring.datasource.url" but has a empty value. v2.2.6.RELEASE break this support.
code in v2.2.5.RELEASE is good and work, why need to change it?
Comment From: rj-hwang
Relate to stackoverflow.com/questions/61247375
Comment From: snicoll
Thanks for reporting the problem and I am not sure what to do about this. This was fixed as part of #19192. If you specify a spring.datasource.uri
, we should honour that and not fallback on an embedded database.
code in v2.2.5.RELEASE is good and work, why need to change it?
It might be working for you but it led to a regression, see #20438
Setting the property to an empty value looks like a corner case to me indeed but I am a bit nervous to change that again. If you want an embedded data source, you shouldn't set spring.datasource.uri
at all. I've flagged this one for team attention to see what the rest of the team thinks.
In the meantime, it would be helpful to share a small sample we can run ourselves.
Comment From: snicoll
TIL that ~
in YAML is used to express null
.
@rj-hwang there's no such thing as setting a property to null
with Spring Boot. The property will always be set and using that yaml trick won't change anything to that. Please consider that going forward.
I saw the reference to your sample here and ran it with 2.2.7.BUILD-SNAPSHOT
. It is working as it was in 2.2.5.RELEASE
. Thank you very much for sharing the sample as it helps us confirming this fixed the issue for you.