栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Spring @Transactional方法-参与交易

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Spring @Transactional方法-参与交易

春季AOP中的代理

使用事务性时,您要处理类的代理,因此在这种情况下:

@Transactionalpublic void doSomeThing(){ // calling this method targets a proxy    doSomeThingElse(); // this method targets the actual class, not the PROXY, // so the transactional annotation has no effect}@Transactionalpublic void doSomeThingElse(){}

您从外部调用代理,但是第二个方法调用是从代理对象内部进行的,因此没有事务支持。所以自然地,它们运行在同一事务中,无论第二种方法中@Transactional批注的值是多少

因此,如果您需要单独的交易,则必须致电

yourservice.doSomething();yourservice.doSomethingElse();

从外面。

整个场景在 **[Spring AOP

了解AOP代理](http://static.springsource.org/spring/docs/3.0.x/spring-framework-
reference/html/aop.html#aop-understanding-aop-
proxies)**(包括此“解决方案”)一章中得到了很好的解释:

从内部访问当前AOP代理对象

public class SimplePojo implements Pojo {   public void foo() {      // this works, but... gah!      ((Pojo) AopContext.currentProxy()).bar();   }   public void bar() {      // some logic...   }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/453372.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号