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

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

问题描述

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

在我的 applicationContext.xml 中?

解决方案

代理和字节码编织方面存在巨大差异.代理只能拦截来自外层空间"的调用,但不能拦截来自对象本身的调用(this.transactionalMethod())

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

如果你使用AspectJ,事务处理代码被编织在T的字节码中,无论调用是来自对象本身还是来自其他对象,它都会被执行.>

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" />

and

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

in my applicationContext.xml?

解决方案

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())

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!

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天全站免登陆