Spring:注释驱动的事务管理器 [英] Spring: Annotation-driven Transaction Manager

查看:239
本文介绍了Spring:注释驱动的事务管理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个新的JPA + Spring项目。有什么区别(对于我作为程序员):

I'm setting up a new, JPA+Spring project. What is the difference (for me as a programmer) between:

<tx:annotation-driven transaction-manager="transactionManager" />

<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager" />

推荐答案

代理和字节代码之间存在巨大差异。
代理只能在调用来自外部空间时拦截,但如果调用来自对象本身则不会拦截(this.transactionMethod())

There is a huge difference between Proxies and byte code weaven aspects. Proxies can only intercept if the invocation comes from "outer space", but not if the invocation comes from the object itself (this.transactionalMethod())

这意味着如果你有一个带有两个方法的类,T和B.方法 T 有一个事务注释,方法 B 通过this.T()调用 T ,然后永远不会调用代理(对于 T )所以在这种情况下没有事务处理!

This means if you have a Class with two methods, T and B. Method T has a transaction annotation, and method B invokes T by "this.T()", then the proxy is never invoked (for T) so there is no transaction handling in this case!

如果使用AspectJ,事务处理代码在字节代码中是weaven T ,无论调用是来自对象本身还是来自其他对象,都将执行。

If you use AspectJ the transaction handling code is weaven in the byte code of T, and it will be executed no matter if the invocation comes from the object itself or from an other object.

这篇关于Spring:注释驱动的事务管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆