Align TransactionManagementConfigurer support in TestContext framework with production
See original GitHub issueAffects: Spring Framework 4.3.0+
When @Primary
support was added for spring-test
in 677a321, the lookup was added before TransactionManagementConfigurer
lookup and not after as it should have been, given that TransactionManagementConfigurer
should take higher precedence. In fact maybe it should be the first check even before the beansOfTypeIncludingAncestors
lookup as the configurer can construct a TransactionManager
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 a TransactionManagementConfigurer
.
Current result
Test uses the @Primary
annotated bean.
Expected result
Test should use the bean provided by TransactionManagementConfigurer
.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Testing - Spring
The Spring TestContext Framework provides several abstract support classes that simplify the writing of integration tests. These base test ...
Read more >Programmatic Transactions in the TestContext Framework
In this article, we'll see how to programmatically interact with automatic transactions set up by Spring in transactional tests. 2.
Read more >Spring Framework Reference Documentation
The Java Messaging Service (JMS) module contains features for producing and consuming messages. The Transaction module supports programmatic and declarative ...
Read more >Spring/CHANGELOG and Spring Releases | LibHunt
... Avoid using regex matching for static patterns #24887; ✓ Align TransactionManagementConfigurer support in TestContext framework with production #24869 ...
Read more >所有类 (Spring Framework 4.3.30.RELEASE API)
Abstract base test class which integrates the Spring TestContext Framework with explicit ApplicationContext testing support in a JUnit environment.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
TransactionManagementConfigurer
is the top priority unless the annotation is qualified, so by my understanding the code block in lines 187-191 (single transaction manager bean) should be moved afterTransactionManagementConfigurer
block@friscoMad, thanks for the feedback.
According to the Javadoc for
TransactionManagementConfigurer.annotationDrivenTransactionManager()
: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 715e8c9ef6ec58fd55b7e11e35586a0806b76cc0.