Spring nested transactions

前端 未结 5 1290
野趣味
野趣味 2021-02-01 03:05

In my Spring Boot project I have implemented following service method:

@Transactional
public boolean validateBoard(Board board) {
    boolean result = false;
            


        
5条回答
  •  失恋的感觉
    2021-02-01 03:39

    Using "self" inject pattern you can resolve this issue.

    sample code like below:

    @Service @Transactional
    public class YourService {
       //... your member
    
       @Autowired
       private YourService self;   //inject proxy as an instance member variable ;
    
       @Transactional(propagation= Propagation.REQUIRES_NEW)
       public void methodFoo() {
          //...
       }
    
       public void methodBar() {
          //call self.methodFoo() rather than this.methodFoo()
          self.methodFoo();
       }
    }
    

    The point is using "self" rather than "this".

提交回复
热议问题