The default transaction manager used by spring annotations

https://stackoverflow.com/questions/27239007/which-is-the-default-transaction-manager-the-transactional-uses

 

 

spring default transaction manager

 

There are no answers and no documentation. .

 

<tx:annotation-driven transaction-manager="transactionManager2"/>  

  <tx:annotation-driven transaction-manager="transactionManager"/> 

Thing Code Testing and Code Debugging Discovery

Only the first configuration works

 

Code debugging:

spring-tx-3.2.1.RELEASE.jar

package org.springframework.transaction.config

AnnotationDrivenBeanDefinitionParser

Entry: 77 lines of parse method

The breakpoint will debug and enter twice,

 

The first element is transactionManager2

Then AopAutoProxyConfigurer.configureAutoProxyCreator(element, parserContext) will be called;

!parserContext.getRegistry().containsBeanDefinition(txAdvisorBeanName) 为true

 

Call registerTransactionManager(element, interceptorDef); register as transactionManager2

 

The second element is transactionManager, but !parserContext.getRegistry().containsBeanDefinition(txAdvisorBeanName) is false

Jump out of the if block directly

 

Summary: Configure multiple tx:annotation-driven, only the first one is valid

 

 

 

 

 

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326643282&siteId=291194637