Running two tests with different application contexts will cause the same aspectj AbstractTransactionAspect instance to be reused, (but setBeanFactory is called also for the second test context).

Beceause TransactionAspectSupport.transactionManagerCache is not cleared for the second test context, the transactionManager from first test is used, which can lead to issues.

Created example application where first test closes the db connection, causing failure in second test (if run afterwards in same jvm).

I'm not sure what correct solution can be: * clearing transactionManagerCache on TransactionAspectSupport.setBeanFactory can help, but would this be safe when running tests in parallel? if first test context is later reused, would setBeanFactory be called again? * I think the real issue is that same AbstractTransactionAspect instance is reused between test contexts, and we should have separate instances spring-aspects-issue-cachedtm.zip

Comment From: sbrannen

Hi @andreiamariei,

Thanks for the report; however, this is a known limitation.

I am therefore closing this as a:

  • Duplicate of #11019

Regards,

Sam

Comment From: andreiamariei

Thank you for your reply @sbrannen, but can't Spring at least clear transactionManagerCache on TransactionAspectSupport.setBeanFactory ? Wouldn't this make TransactionAspectSupport more resilient, as previous beanFactory was used to initialize the transactionManagerCache?