开发者

How can I see from which TransactionManager given transaction is created in Spring 3.0

开发者 https://www.devze.com 2023-01-12 16:45 出处:网络
In my spring configuration I have two transaction managers defined for two different databases. Is there a way in spr开发者_StackOverflow中文版ing to check on runtime whether given method is running i

In my spring configuration I have two transaction managers defined for two different databases. Is there a way in spr开发者_StackOverflow中文版ing to check on runtime whether given method is running inside transaction and secondly (and more importantly) from which transaction manager was this transaction created.


You can use the TransactionSynchronizationManager. It has a number of methods to tell you whether the transaction is active and what's its name. You can get the resource map (getResourceMap()) and verify what's inside.

Everything in that class is ThreadLocal, so it will give you information about the current transaction.

However, the documentation says:

To be used by resource management code but not by typical application code.

It is not clear why you would need that information. Spring uses declarative transactions so that the actual code does not have to know about (and handle) transactional behaviour. If you need to differentiate between transaction managers in the code, then something might be wrong.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号