Is the @ Transactional annotation on the called method completely invalid in the self-call in the Spring transaction?

for example

public class ShopServiceImpl{
    
    @Transactional
    public void do1(){
        do2();
    }
    
    @Transactional
    public void do2(){
        ....
    }   
}

as in the code above, when do1 calls do2 (), are the @ Transactional, on do2 () invalid with defined propagation attributes such as PROPAGATION_NOT_SUPPORTED,PROPAGATION_NEVER, or timeout?

May.08,2021

Yes, if you need to add a transaction, you can try to get the proxy object through AopContext.currentProxy () , and then call do2.


has encountered this situation, the practice at that time is to inject its own proxy object, and then use this object to call the method

@Autowired
private ShopServiceImpl impl;

@Transactional
public void do1(){
    impl.do2();
}

Menu