In 2.4.3 if there are multiple databases in a spring boot app, and there are schema/data scripts specified for both of them, then only the one where the DataSource bean is created first will be executed.
The problem is in my opinion is here:
https://github.com/spring-projects/spring-boot/blob/49ea417fea07f5c48e4356abf0f65ff3b6a55e49/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerPostProcessor.java#L51
The DataSourceInitializerInvoker will be created under the name of the class, so when the second one will be created for the second database, the previous one will be reused.
Comment From: snicoll
if there are multiple databases in a spring boot app, and there are schema/data scripts specified for both of them, then only the one where the DataSource bean is created first will be executed.
I can only guess that you have multiple DataSourceProperties
bound to multiple prefixes and then some configuration properties that point to the relevant schema/data sql files. Unfortunately, binding those keys is not enough for datasource initialization to kick in for them.
Spring Boot really supports the initialization of one datasource using the primary DataSourceProperties
. We've been reviewing that support in Spring Boot 2.5 to make that a bit more explicit and it is a work in progress. If you need to initialize multiple datasources, you'll need to take care of that the same way you did to register the DataSource
themselves.