@Transactional failure of several scenes

1. An @Transactional approach was the absence of @Transactional method call, it will lead role Transactional failure. The situation is most likely to occur.

  Why would that happen? In fact, this is due to the use of Spring AOPagents caused, because only when the transaction method is called code outside the current class, will be made Springto manage the proxy object generated.

2. The method of non-public transaction annotation. @Transactional will fail.

  The reason: when the agent is to be in Spring AOP, transaction interceptor to intercept before and after the target method, DynamicAdvisedInterceptorIntercept method will get Transactional annotation transaction configuration information,

Agent because Spring AOP, as shown above TransactionInterceptor (transaction interceptor) to intercept target before and after performing the method, DynamicAdvisedInterceptor (CglibAopProxy inner classes) the intercept method or JdkDynamicAopProxy invoke method indirectly calling AbstractFallbackTransactionAttributeSource the computeTransactionAttribute method indirectly calling AbstractFallbackTransactionAttributeSource the computeTransactionAttribute method, which You will get transactional annotation transaction configuration information. He will first qualifier transaction method of verification is not public, not public property is not acquired @Transactional configuration information.
Configuration issues propagation properties of 3.Transactional transaction configuration attributes.
  When the propagation properties are configured to:
TransactionDefinition.PROPAGATION_SUPPORTS : If the current transaction exists, it is added to the transaction; if no transaction, non-transactional way places continue to run.        TransactionDefinition.PROPAGATION_NOT_SUPPORTED : Running in non-transactional way, if the current transaction exists, put the current transaction pending.     TransactionDefinition.PROPAGATION_NEVER : Running in non-transactional way, if the current transaction exists, an exception is thrown
 

4. There is also a case where:

  A method annotated by the transaction, B has also been annotated transaction method in a class.

@ Transactional

 public void A(){

  try{

  this.B();

  }catch(Exception e){

    logger.error();

  }

 

}

However, in the implementation of the method B is given, but is abnormal A catch live, then the transaction will fail.

Guess you like

Origin www.cnblogs.com/jiaoxiaoting/p/12548146.html