org.springframework.transaction.annotation

## Interface TransactionManagementConfigurer

    public interface TransactionManagementConfigurer

Interface to be implemented by @`Configuration` classes annotated with @`EnableTransactionManagement` that wish or need to specify explicitly the `PlatformTransactionManager` bean to be used for annotation-driven transaction management, as opposed to the default approach of a by-type lookup. One reason this might be necessary is if there are two `PlatformTransactionManager` beans present in the container.

See @`EnableTransactionManagement` for general examples and context; see `annotationDrivenTransactionManager()` for detailed instructions.

Note that in by-type lookup disambiguation cases, an alternative approach to implementing this interface is to simply mark one of the offending `PlatformTransactionManager` `@Bean` methods as @`Primary`.

Since:
  3.1
Author:
  Chris Beams
See Also:
  `EnableTransactionManagement`, `Primary`

### Method Summary

Methods
`PlatformTransactionManager` `annotationDrivenTransactionManager()` Return the transaction manager bean to use for annotation-driven database transaction management, i.e.

### Method Detail

#### annotationDrivenTransactionManager

    PlatformTransactionManager annotationDrivenTransactionManager()

Return the transaction manager bean to use for annotation-driven database transaction management, i.e. when processing `@Transactional` methods.

There are two basic approaches to implementing this method:

### 1. Implement the method and annotate it with `@Bean`

In this case, the implementing `@Configuration` class implements this method, marks it with `@Bean` and configures and returns the transaction manager directly within the method body:

     @Bean
     @Override
     public PlatformTransactionManager annotationDrivenTransactionManager() {
         return new DataSourceTransactionManager(dataSource());
     }

### 2. Implement the method without `@Bean` and delegate to another existing `@Bean` method

     @Bean
     public PlatformTransactionManager txManager() {
         return new DataSourceTransactionManager(dataSource());
     }

     @Override
     public PlatformTransactionManager annotationDrivenTransactionManager() {
         return txManager(); // reference the existing @Bean method above
     }

If taking approach #2, be sure that only one of the methods is marked with `@Bean`!

In either scenario #1 or #2, it is important that the `PlatformTransactionManager` instance is managed as a Spring bean within the container as all `PlatformTransactionManager` implementations take advantage of Spring lifecycle callbacks such as `InitializingBean` and `BeanFactoryAware`.