One Service method invoke inner multiple method for Spring transaction

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

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

package com.bluesky         


        
3条回答
  •  攒了一身酷
    2020-12-20 18:03

    I understand your problem. There are some technically complex ways to get it work, but we don't usually consider they are worth it. I suggest another approach, simple and powerful, that actually improves your code.

    Instead of having them on the same Spring bean, have them on two different Beans, B being injected into A.

    I known I'm not answering your question, but think about the advantages :

    • Dead simple, it will cost you very little time now.
    • To require a new transaction, B is probably a different concern. Having a different concern is a different class seem exactly what we are looking for, good design.
    • You don't have anything new and complex to explain to your colleagues (or document for the future developers), it simplicity makes it immediately understandable.

提交回复
热议问题