开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜