I have an application.yml config file in a Spring Boot 2.2.4 app with the following entry:

spring.datasource.url: ${DATA_SOURCE_URL}

DATA_SOURCE_URL is available only when running the app locally, not in the cloud.

In the cloud (Pivotal Cloud Foundry) we have a PostgreSQL service that injects the data source connection properties automatically using Spring Cloud Connectors. This work perfectly in 2.2.4.

When bumping up the Spring Boot version to 2.2.5 the app won't start:

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'DATA_SOURCE_URL' in value "${DATA_SOURCE_URL}"

Comment From: wilkinsona

@fedelopez Thanks for the report. Could you please try with a 2.2.6 snapshot (available from https://repo.spring.io/snapshot). I am wondering if the problem that you are seeing is a duplicate of #20432.

Comment From: fedelopez

I've tried with version 2.2.6.BUILD-SNAPSHOT from the snapshot repo but I still get the same error.

Only works when I revert back to 2.2.4.RELEASE.

Comment From: wilkinsona

Thanks for trying out a 2.2.6 snapshot. Can you please share a small sample that reproduces the problem so that we can investigate further?

Comment From: spring-projects-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Comment From: fedelopez

You can try this repo. If you push it to Pivotal Web Services will not work with 2.2.5 and 2.2.6.BUILD-SNAPSHOT: https://github.com/fedelopez/spring-boot-issue-20438

Comment From: wilkinsona

Thanks for the sample. I believe the change in behaviour is due to this change.

Comment From: wilkinsona

The problem can be reproduced with this test in DataSourceAutoConfigurationTests:

@Test
void whenThereIsAUserProvidedDataSourceAnUnresolvablePlaceholderDoesNotCauseAProblem() {
    this.contextRunner.withUserConfiguration(TestDataSourceConfiguration.class)
        .withPropertyValues("spring.datasource.url:${UNRESOLVABLE_PLACEHOLDER}")
        .run((context) -> assertThat(context).getBean(DataSource.class).isInstanceOf(BasicDataSource.class));
}

Comment From: wilkinsona

@fedelopez You can work around the problem for now by removing spring.datasource.url=${DATA_SOURCE_URL} from application.properties. It serves no purpose when deploying to PWS as the datasource is provided by Spring Cloud Connectors. This causes the auto-configured datasource to back off.

We need to fix things in 2.2.6 so that it can back off without the unresolvable placeholder causing a problem.

Comment From: scottfrederick

@fedelopez Also note that Spring Cloud Connectors is in maintenance mode, and the Java CFEnv project is preferred going forward. Java CFEnv is much more Boot-friendly than Connectors, as CFEnv sets properties that allow Spring Boot auto-configuration to create connections whereas Connectors creates connections on its own which causes Boot auto-configuration to back off.

With Java CFEnv, you still wouldn't need to set spring.datasource.url=${DATA_SOURCE_URL} in application.properties, as CFEnv would set this for you when it detects that the app is running on CF and has a bound database service.