One Service method invoke inner multiple method for Spring transaction

前端 未结 3 1237
情话喂你
情话喂你 2020-12-20 17:13
package com.bluesky;

public interface FooServiceIface {
    public  void insertA();
    public void insertB();
}

package com.bluesky         


        
3条回答
  •  清酒与你
    2020-12-20 17:49

    KLE's answer is solid advice. Just to complete the picture, there is a workaround, but it breaks everything AOP stands for:

    public void insertA() {
        this.getJdbcTemplate().execute("insert student(name) values('stuA')");
        // this works, but... gah!
        ((FooServiceIface) AopContext.currentProxy()).insertB();
        int i=10/0;
    }
    

    Reference:

    • 7.6.1. Understanding AOP proxies
    • AopContext javadoc

提交回复
热议问题