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
AnnotationTransactionAspect retains reference to JpaTransactionManager from closed context [SPR-12518] #17123
Comments
Sam Brannen commented
So, thanks for submitting the example project! Please see the Analysis in this issue's updated description for further details. |
Sam Brannen commented I'm still pondering what the best solution to this issue is; however, in the meantime I have a work-around for you. In your Gradle build configuration: project.ext {
springVersion = "4.1.2.RELEASE"
// ...
}
// ...
dependencies {
// ...
testCompile "org.springframework:spring-aspects:$springVersion"
// ...
} In @After
public void cleanUpAspects() {
AnnotationTransactionAspect.aspectOf().setTransactionManager(null);
} Let me know if that works for you! Thanks, Sam |
Marek Wiącek commented Invoking AnnotationTransactionAspect.aspectOf().setTransactionManager(null) fixes the problem, thank you. |
Sam Brannen commented Thanks for providing feedback, Marek! And... I'm glad that work-around fixes the issue for you. :) |
Stéphane Nicoll commented We had the same issue with the Cache operation metadata that are .... cached as well. It was only a problem in test really; exactly as in this case. It turns out that we fixed that problem by making the aspect aware that the context has been closed. We can apply the same trick here. |
Sam Brannen commented Sounds good! |
Stéphane Nicoll commented Applied the same trick as the |
Sam Brannen commented Looks Good, Stéphane. Thanks! |
Turbanov Andrey commented
|
Marek Wiącek opened SPR-12518 and commented
Original Input From Reporter
@DirtiesContext
is broken in 4.1.0:spring-test
fails to recreate a context containing a JPAEntityManager
if a test class is annotated with@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
. Interestingly, this only happens in AspectJ mode for@Transactional
support.See the attached program to see how to reproduce the problem.
Downgrading the version number in
build.gradle
to 4.0.8.RELEASE fixes this problem. Apparently this is a regression introduced in4.1.0.RELEASE
.Analysis
The behavior experienced in the example project is a direct result of the caching introduced in #16570.
Specifically, the
determineTransactionManager()
method inTransactionAspectSupport
(which is a superclass ofAnnotationTransactionAspect
which in turn provides AspectJ-based support for@Transactional
in Spring) now retains a reference to thePlatformTransactionManager
. Since the aspect is a singleton within the class loader, its internal state does not get automatically reset when the application context is closed via@DirtiesContext
semantics.In other words, the testing framework does in fact close the application context due to
@DirtiesContext
semantics, but theAnnotationTransactionAspect
retains a reference to theJpaTransactionManager
from the closed application context, and that transaction manager in turn retains a reference to the closedEntityManagerFactory
. This is evident in the resulting stack trace.Deliverables
Affects: 4.1 GA
Attachments:
Issue Links:
@Configurable
objects should work across test suites@Transactional
qualifier is ignored by TransactionAspectSupport if default transaction manager is setReferenced from: commits ca91956, fd7153f
0 votes, 6 watchers
The text was updated successfully, but these errors were encountered: