question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Align TransactionManagementConfigurer support in TestContext framework with production

See original GitHub issue

Affects: 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:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
friscoMadcommented, May 11, 2020

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 after TransactionManagementConfigurer block

0reactions
sbrannencommented, May 11, 2020

@friscoMad, thanks for the feedback.

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.

According to the Javadoc for TransactionManagementConfigurer.annotationDrivenTransactionManager():

it is important that the PlatformTransactionManager instance is managed as a Spring bean within the container since most PlatformTransactionManager implementations take advantage of Spring lifecycle callbacks such as InitializingBean and BeanFactoryAware.

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found