-
Notifications
You must be signed in to change notification settings - Fork 41.6k
Initialize BatchDataSourceInitializer eagerly #27144
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
Conversation
|
Thanks for the proposal, but this change doesn't feel quite right to me. I think it should be possible for the initialiser to be lazy and for the schema to then be initialized prior to first use of the |
|
@wilkinsona Thanks for the quick and insightful feedback! I'd be happy to re-work the PR according to your suggestion to instantiate the Would it be possible to auto-configure a Regarding the suggested auto-configured |
|
Sorry, I didn't explain myself clearly earlier.
When I said this above, I meant that it should already work like this. I've just tried with our Batch smoke test with lazy init enabled and it doesn't work. In Boot 2.4, it fails with the following: This tells me that we are missing some dependency relationships between beans. It only works at the moment in the non-lazy case as the Batch database tables aren't being accessed until after the application context has refreshed. If something tried to use those tables during refresh, it may fail as there's no guarantee that the initializer will have run. Thanks for bringing the problem to our attention. I don't think that changing the eagerness with which the relevant beans are initialized is the right way to fix this. I've opened #27193 so that we can take a different approach. |
Spring Boot apps with autoconfiguration for Spring Batch currently do not initialize the data source with
BatchDataSourceInitializerifspring.main.lazy-initializationis set totrueindependent of what the propertyspring.batch.jdbc.initialize-schemais set to.The issue can be worked around by users with a
LazyInitializationExcludeFilterbut a consistent behavior forspring.batch.jdbc.initialize-schemaindependent of lazy or eager initialization would be nice.