org.springframework.transaction.TransactionManager Java Examples

The following examples show how to use org.springframework.transaction.TransactionManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TransactionManagementConfigurer.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * 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">
 * &#064;Bean
 * &#064;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">
 * &#064;Bean
 * public PlatformTransactionManager txManager() {
 *     return new DataSourceTransactionManager(dataSource());
 * }
 *
 * &#064;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();
 
Example #2
Source File: TransactionAspectSupport.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * 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;
}
 
Example #3
Source File: TransactionAspectSupport.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * 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;
}