-
Notifications
You must be signed in to change notification settings - Fork 2.4k
BATCH-2294: Don't replace my PlatformTransactionManager with a new one #609
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
BATCH-2294: Don't replace my PlatformTransactionManager with a new one #609
Conversation
For some reason DefaultBatchConfigurer decides that you can't possibly already have a PlatformTransactionManager and makes a new one for you. Because of the way Spring's bean factory works, this new one is sometimes created after the one you _actually_ wanted, and it _replaces_ the real one in your application with a lame one that is useless. This patch changes the implementation of DefaultBatchConfigurer so it tries to autowire an existing bean and only makes a new one if one doesn't exist already.
This PR tries to fix the same issue as #415, which has merge conflicts. I took what seems like the simpler route. I was unsure how to create a test for this situation. I'm open to suggestions. I'm also happy to make adjustments to the way I fixed it if anyone has a better suggestion. |
logger.warn("No datasource was provided...using a Map based JobRepository"); | ||
|
||
if(this.transactionManager == null) { | ||
if(this.transactionManager == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This formatting seems inconsistent with the Spring Framework Code Style. There should be a space between "if" and the paren. I mimicked what was already in the file because I felt it would be weird to mix the style within a single file. I'm happy to fix the formatting if you'd like me to, but I want to make sure the approach I took is acceptable before I go to that effort.
@elreydetodo We actually reviewed these PRs internally yesterday. We liked the structure of the if statements in the init method better in #415 but we liked your logging additions. If you want to apply the changes he made to your PR and add a test, we'd be happy to merge it. cc: @benas |
I wrote a test suite here: fmbenhassine@b6fa592 While testing this PR, I found a couple of issues:
Those tests are failing because of the following sequence:
As mentioned in #415, I think we should not try to autowire the transaction manager. If the user wants a custom transaction manager, he has to provide a custom |
For some reason DefaultBatchConfigurer decides that you can't possibly
already have a PlatformTransactionManager and makes a new one for you.
Because of the way Spring's bean factory works, this new one is
sometimes created after the one you actually wanted, and it replaces
the real one in your application with a lame one that is useless.
This patch changes the implementation of DefaultBatchConfigurer so it
tries to autowire an existing bean and only makes a new one if one
doesn't exist already.