Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unresolvable placeholder in the value of spring.datasource.url causes a startup failure even when there is a user-provided DataSource bean #20438

Closed
fedelopez opened this issue Mar 10, 2020 · 9 comments
Assignees
Labels
type: regression A regression from a previous release
Milestone

Comments

@fedelopez
Copy link

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}"

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 10, 2020
@wilkinsona
Copy link
Member

@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.

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Mar 10, 2020
@fedelopez
Copy link
Author

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.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Mar 14, 2020
@wilkinsona
Copy link
Member

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?

@wilkinsona wilkinsona added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Mar 14, 2020
@spring-projects-issues
Copy link
Collaborator

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.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder We've sent a reminder that we need additional information before we can continue label Mar 21, 2020
@fedelopez
Copy link
Author

fedelopez commented Mar 22, 2020

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

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue status: feedback-reminder We've sent a reminder that we need additional information before we can continue labels Mar 22, 2020
@wilkinsona
Copy link
Member

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

@wilkinsona
Copy link
Member

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));
}

@wilkinsona
Copy link
Member

@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.

@wilkinsona wilkinsona changed the title Environment variables with placeholders in application.yml not resolved when running app in cloud Unresolvable placeholder in the value of spring.datasource.url causes a startup failure even when there is a user-provided DataSource bean Mar 23, 2020
@wilkinsona wilkinsona added type: regression A regression from a previous release and removed status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged labels Mar 23, 2020
@wilkinsona wilkinsona added this to the 2.2.6 milestone Mar 23, 2020
@scottfrederick
Copy link
Contributor

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

5 participants