Skip to content

Embedded database initial failed for setting empty spring.database.url #20996

@rj-hwang

Description

@rj-hwang

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?

Metadata

Metadata

Assignees

Labels

type: regressionA regression from a previous release

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions