public class SimplePojo implements Pojo {
//外层方法不标记事务注解:
//这种调用方式,内层事务失效,外层不存在事务,失败,整体未回滚
public void foo() {
// this next method invocation is a direct call on the 'this' reference
this.bar();
}
//外层方法有标记事务注解:
//内层事务失效,外层存在事务,如果内层异常throw出来的话,外层事务会控制整体进行回滚
@Transcation
public void foo() {
// this next method invocation is a direct call on the 'this' reference
this.bar();
}
@Transcation
public void bar() {
// some logic...
}
//private方法默认不会被增强,所以此种写法,内层事务也是不生效的
@Transcation
private void bar() {
// some logic...
}
}
关于类方法调用aop增强失效可以参考:spring aop类方法之间调用 增强失效