-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Align TransactionManagementConfigurer support in TestContext framework with production #24869
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
Comments
This commit introduces an integration test for the status quo in the Spring TestContext Framework (TCF) for multiple transaction managers registered as @primary and via the TransactionManagementConfigurer API. In Spring Framework 5.3 we will revise the transaction manager lookup in TestContextTransactionUtils so that the transaction manager configured via the TransactionManagementConfigurer API is favored over a @primary transaction manager. See gh-24869
Thank you for bringing this to our attention! 👍 There is indeed a discrepancy between the transaction manager lookup algorithm in production code and the algorithm used within the Spring TestContext Framework (TCF). I introduced tests for the status quo for production code in 144b0e1 and for the TCF in a5498ba. In Spring Framework 5.3 we will revise the transaction manager lookup in |
Thank you for such fast reply.
|
This has been addressed in 613bd3b. Feel free to try it out in an upcoming 5.3 M1 snapshot. |
I will try as soon as posible but while the change does fix my initial report and my use case, it still does not replicate production transaction manager lookup, at least by my understanding looking at production code, the |
Reopening to align with production behavior. |
@friscoMad, thanks for the feedback.
According to the Javadoc for
Thus, although the scenario you have described is highly discouraged, it is technically possible and supported in production arrangements. I have therefore further refined the transaction manager lookup in the TestContext framework in 715e8c9. |
Prior to this commit, the Spring TestContext Framework (TCF) favored a @primary transaction manger over one configured via the TransactionManagementConfigurer API, and this contradicts the behavior in production Spring applications. This commit aligns the transaction manger lookup within the TCF so that a transaction manger configured via the TransactionManagementConfigurer API is properly favored over a @primary transaction manager. Closes spring-projectsgh-24869
This commit picks up where 613bd3b left off by ensuring that a transaction manager configured via the TransactionManagementConfigurer API takes precedence over any transaction manager configured as a bean in the ApplicationContext unless @transactional is configured with a qualifier for the explicit transaction manager to use in tests. Closes spring-projectsgh-24869
Affects: Spring Framework 4.3.0+
When
@Primary
support was added forspring-test
in 677a321, the lookup was added beforeTransactionManagementConfigurer
lookup and not after as it should have been, given thatTransactionManagementConfigurer
should take higher precedence. In fact maybe it should be the first check even before thebeansOfTypeIncludingAncestors
lookup as the configurer can construct aTransactionManager
that is not a registered bean (a registered bean could be in the context that is not the one that the configurer will return).Steps to reproduce
Configure a context with a
@Primary TransactionManager
and aTransactionManagementConfigurer
.Current result
Test uses the
@Primary
annotated bean.Expected result
Test should use the bean provided by
TransactionManagementConfigurer
.The text was updated successfully, but these errors were encountered: