I recently upgraded a Spring Boot microservice from v2.6.7 to v2.7.2. In the code, we retrieve database credentials from an AWS parameter store and use them to connect to a Postgres database. We take param values that indicate what to retrieve from the AWS parameter store, retrieve those values and and then add those values to the Spring environment (as spring.datasource.username & spring.datasource.password).
This was working without issue before we upgraded to 2.7.2. However, since the upgrade, we seem to have a timing issue where a database connection is attempted before the values have been retrieved. We don't even reach the code to do the parameter store retrieval before it tries to make the DB connection. However, in my properties file, if I put valid values in the hardcoded parameters below (& uncomment them), the database connection is made and I see the code to go get the AWS parameter store values run, so I know the code is good. The class that does the work of getting the values is @Autowired in my SpringBootApplication class.
spring.datasource.url=jdbc:postgresql://<aws URL>
spring.datasource.username.param=<aws parameter store for username>
spring.datasource.password.param=<aws parameter store for password>
# spring.datasource.username=<a valid hardcoded username>
# spring.datasource.password=<a valid hardcoded pwd>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-bom</artifactId>
<version>1.12.301</version>
<type>pom</type>
</dependency>
Did anything change in the latest Spring Boot version that would affect the nature &/or order of the auto wiring? How can I force the database connection attempt to wait until the DB creds have been retrieved? Any troubleshooting suggestions?