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

Consider initialization of multiple datasources #13417

Closed
krabaey opened this issue Jun 7, 2018 · 9 comments
Closed

Consider initialization of multiple datasources #13417

krabaey opened this issue Jun 7, 2018 · 9 comments
Labels
status: superseded An issue that has been superseded by another

Comments

@krabaey
Copy link

krabaey commented Jun 7, 2018

Sample project in attach with failing test cases, run via mvnw test

Two datasources are configured, each with a schema and data init file, however only the schema and data initialization from the primary datasource is executed.

I would have expected the data/schema init files both would be executed in their respective configured datasource.

Main reason seems to be that the spring DataSourceInitializerPostProcessor requests a DataSourceInitializerInvoker singleton which will then only execute intialization once.

A second issue seems to be that the DataSourceInitializerInvoker does not check the DataSourceSchemaCreatedEvent source to match the current datasource, so it might react to the wrong one.

Issue seems to be present from at least Spring Boot 2.0.0
demo.zip

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 7, 2018
@philwebb
Copy link
Member

philwebb commented Jun 7, 2018

This is the expected behavior with the current implementation. The initializer currently only works with the @Primary datasource. The reason that foo-schema.sql is used is because you're also registering a DataSourceProperties bean as @Primary which will replace the usual spring.datasource properties.

So multiple datasource you'll currently need to use ResourceDatabasePopulator directly.

@philwebb philwebb changed the title When configuring multiple datasources only schema/data init from primary datasource is executed Consider initialization of multiple datasources Jun 7, 2018
@philwebb
Copy link
Member

philwebb commented Jun 7, 2018

See also #9528

@philwebb philwebb added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 7, 2018
@snicoll
Copy link
Member

snicoll commented Jun 8, 2018

We have discussed the possibility to auto-configure multiple data sources and didn’t execute on it. For that reason, I think this issue should be closed.

@wilkinsona
Copy link
Member

But with #9528 we may end up with an API that can be used to register a DataSource for initialisation. We'd then use that API for the auto-configured DataSource and make it available to users for use with their own, manually configured data sources. If anything, I could see this being or becoming a duplicate of #9528.

@yhjlsy123

This comment has been minimized.

@yhjlsy123

This comment has been minimized.

@snicoll

This comment has been minimized.

@philwebb
Copy link
Member

See #15732

@philwebb philwebb added the status: pending-design-work Needs design work before any code can be developed label Jun 14, 2019
@philwebb philwebb modified the milestone: 2.x Jun 14, 2019
@philwebb philwebb added status: superseded An issue that has been superseded by another and removed status: pending-design-work Needs design work before any code can be developed type: enhancement A general enhancement labels Jun 14, 2019
@philwebb
Copy link
Member

philwebb commented Jun 14, 2019

Closing in favor of #9528

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: superseded An issue that has been superseded by another
Projects
None yet
Development

No branches or pull requests

6 participants