This PR introduces a DataSourceBuilderCustomizer. This allows customizing only parts of the DataSource without creating a full new DataSource. This is the JDBC equivalent to R2DBC's ConnectionFactoryOptionsBuilderCustomizer.

My real world use case is connecting to AWS RDS using IAM. The AWS SDK can generate a password with the GenerateAuthenticationTokenRequest function. I only want to set the password programmatically and not mess with any other part of the Boot provided Data Source.

https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/rds/RdsUtilities.html#generateAuthenticationToken(software.amazon.awssdk.services.rds.model.GenerateAuthenticationTokenRequest

Comment From: pivotal-cla

@eduanb Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

Comment From: pivotal-cla

@eduanb Thank you for signing the Contributor License Agreement!

Comment From: vpavic

My real world use case is connecting to AWS RDS using IAM. The AWS SDK can generate a password with the GenerateAuthenticationTokenRequest function.

Are you aware of AWS JDBC Driver which has support for exactly this use case?

Comment From: snicoll

Thanks for the PR @eduanb but we're not keen to introduce such customizers. DataSourceBuilder is also used in custom datasources scenario and having the customizer there could add some confusion.

The customizer isn't required in your scenario. @vpavic offered one option (although I didn't review it). You could also contribute a PropertySource for spring.datasource.password, see this section.

Or you can contribute your DataSource and still apply Spring Boot's default, see this section, using the existing DataSourceProperties rather than creating your own.