spring propagation mechanism Precautions

In the spring of the same class which propagation mechanism is inoperative for example in the implementation of the method call saveA C Method C is inserted propagation properties is provided without the use of things

But the effect is saveA execution method causes a rollback record C C denotes that the isolation level set method does not work after the throw.

 @Transactional
    public void  saveA() throws  Exception{
         C();
         throw  new RuntimeException();
    }



    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public void C() throws Exception {
        mapper.insertEntity(entity);
    }
Next, create a new class serviceB

@Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public void B() throws Exception {
        mapper.insertEntity(entity);
    }
@Transactional
    public void  saveA() throws  Exception{
        serviceB.B();
         throw  new RuntimeException();
    }



    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public void C() throws Exception {
        mapper.insertEntity(entity);
    }

At this time, the recording method B call saveA no rollback mechanism that is spring for propagation and then to the same class class method calls the mutual isolation level is ineffective.

This method is an internal class by class AOP CglibAopProxy the spring of DynamicAdvisedInterceptor calls, and DynamicAdvisedInterceptor inherited MethodInterceptor, to intercept method calls, and to obtain the call chain.


If the method is invoked in the same class, the method can not be intercepted to the interceptor, the transaction will not work and therefore, the method must be put another class, and the class injection by spring



Published 55 original articles · won praise 31 · views 80000 +

Guess you like

Origin blog.csdn.net/zengfanwei1990/article/details/79105620