Spring-cloud-aws: RDS bean does not replace properties for password or dbInstanceIdentifier

Created on 25 Oct 2018  路  5Comments  路  Source: spring-cloud/spring-cloud-aws

When creating an RDS datasource, parameters in the password or db-instance-identifier fields are not replaced. This is contrary to what is shown in the documentation, at least for the password:
https://cloud.spring.io/spring-cloud-aws/spring-cloud-aws.html#_data_access_with_jdbc. This issue has been found when using both the @EnableRdsInstance annotation, as well as an xml bean.

The version of Spring cloud I am using is 2.0.0.RELEASE, and the Spring boot version is 2.0.6.RELEASE.

Here is the code to reproduce with @EnableRdsInstance:

@Configuration
@EnableRdsInstance(
        dbInstanceIdentifier = "${rds.db-instance-identifier}",
        databaseName = "${rds.database-name}",
        username = "${rds.username}",
        password = "${rds.password}"
)
public class RdsConfig {
}

The xml bean that can also reproduce this issue:

<jdbc:data-source
         db-instance-identifier="${rds.db-instance-identifier}"
         database-name="${rds.database-name}"
         username="${rds.username}"
         password="${rds.password}">
</jdbc:data-source>

In both cases, username and database-name are replaced with the values for the corresponding parameters. However, db-instance-identifier and password are left as ${rds.db-instance-identifier} and ${rds.password}.

Upon investigation, the difference that I find between the username and database-name field and the db-instance-identifier and password fields is that the password and db-instance-identifier is passed into the constructor of AmazonRdsDataSourceFactoryBean, where as the username and database-name is set using the setter. The org.springframework.context.support.PropertySourcesPlaceholderConfigurer#postProcessBeanFactory(), which replaces ${...} placeholders in bean definitions, is not called until after the constructor of AmazonRdsDataSourceFactoryBean, and since the db-instance-identifier or password are already set, they cannot be replaced by the resolved properties.

Hardcoding the db-instance-identifier or password here is not an option. I also realise that the data sources can also be configured using the Spring Boot configuration files, where the password property replacement works; however, property replacement on the db-instance-identifier is still not supported there.

rds bug

Most helpful comment

Hello,

is this bug still open ?
Or is it fixed in another ticket ?
I encounter the same issue.

All 5 comments

Hello,

is this bug still open ?
Or is it fixed in another ticket ?
I encounter the same issue.

It seems to be still open, I submitted a related issue with enhancement proposals: https://github.com/spring-cloud/spring-cloud-aws/issues/495

I have tried to reproduce the bug but not succeed. Are you still encountering the problem? @rjansem @engineal

@mkatircioglu I just tested using org.springframework.cloud:spring-cloud-aws-jdbc:2.2.2.RELEASE and this issue is resolved. I am able to now use parameters in the password and db-instance-identifier fields using the methods I outlined in my issue. Thank you for checking in.

@engineal thanks for an update!

Was this page helpful?
0 / 5 - 0 ratings