Skip to content

常用框架/重要知识点/Spring事务详解/@Transactional 注解使用详解/Spring AOP 自调用问题 #2091

Closed
@JianingWu911

Description

@JianingWu911

基于动态代理的AOP,在自调用时候也可以正常开启事务。
如下面代码:

@Service
public class MyService {

private void method1() {
     ((MyService)AopContext.currentProxy()).method2(); // 先获取该类的代理对象,然后通过代理对象调用method2。
     //......
}
@Transactional
 public void method2() {
     //......
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request or suggestion

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions