下面列出了org.springframework.transaction.annotation.TransactionManagementConfigurer#org.springframework.transaction.TransactionManager 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Return the default transaction manager bean to use for annotation-driven database
* transaction management, i.e. when processing {@code @Transactional} methods.
* <p>There are two basic approaches to implementing this method:
* <h3>1. Implement the method and annotate it with {@code @Bean}</h3>
* In this case, the implementing {@code @Configuration} class implements this method,
* marks it with {@code @Bean} and configures and returns the transaction manager
* directly within the method body:
* <pre class="code">
* @Bean
* @Override
* public PlatformTransactionManager annotationDrivenTransactionManager() {
* return new DataSourceTransactionManager(dataSource());
* }</pre>
* <h3>2. Implement the method without {@code @Bean} and delegate to another existing
* {@code @Bean} method</h3>
* <pre class="code">
* @Bean
* public PlatformTransactionManager txManager() {
* return new DataSourceTransactionManager(dataSource());
* }
*
* @Override
* public PlatformTransactionManager annotationDrivenTransactionManager() {
* return txManager(); // reference the existing {@code @Bean} method above
* }</pre>
* If taking approach #2, be sure that <em>only one</em> of the methods is marked
* with {@code @Bean}!
* <p>In either scenario #1 or #2, it is important that the
* {@code PlatformTransactionManager} instance is managed as a Spring bean within the
* container as all {@code PlatformTransactionManager} implementations take advantage
* of Spring lifecycle callbacks such as {@code InitializingBean} and
* {@code BeanFactoryAware}.
* @return a {@link org.springframework.transaction.PlatformTransactionManager} or
* {@link org.springframework.transaction.ReactiveTransactionManager} implementation
*/
TransactionManager annotationDrivenTransactionManager();
/**
* Specify the <em>default</em> transaction manager to use to drive transactions.
* This can either be a traditional {@link PlatformTransactionManager} or a
* {@link ReactiveTransactionManager} for reactive transaction management.
* <p>The default transaction manager will be used if a <em>qualifier</em>
* has not been declared for a given transaction or if an explicit name for the
* default transaction manager bean has not been specified.
* @see #setTransactionManagerBeanName
*/
public void setTransactionManager(@Nullable TransactionManager transactionManager) {
this.transactionManager = transactionManager;
}
/**
* Return the default transaction manager, or {@code null} if unknown.
* This can either be a traditional {@link PlatformTransactionManager} or a
* {@link ReactiveTransactionManager} for reactive transaction management.
*/
@Nullable
public TransactionManager getTransactionManager() {
return this.transactionManager;
}