Browse Source

Polishing

pull/722/merge
Juergen Hoeller 10 years ago
parent
commit
1cd4433621
  1. 6
      spring-tx/src/main/java/org/springframework/transaction/annotation/AbstractTransactionManagementConfiguration.java
  2. 33
      spring-tx/src/main/java/org/springframework/transaction/annotation/TransactionManagementConfigurer.java

6
spring-tx/src/main/java/org/springframework/transaction/annotation/AbstractTransactionManagementConfiguration.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -41,7 +41,7 @@ public abstract class AbstractTransactionManagementConfiguration implements Impo
protected AnnotationAttributes enableTx; protected AnnotationAttributes enableTx;
/** /**
* Default transaction manager. * Default transaction manager, as configured through a {@link TransactionManagementConfigurer}.
*/ */
protected PlatformTransactionManager txManager; protected PlatformTransactionManager txManager;
@ -54,7 +54,7 @@ public abstract class AbstractTransactionManagementConfiguration implements Impo
"@EnableTransactionManagement is not present on importing class " + importMetadata.getClassName()); "@EnableTransactionManagement is not present on importing class " + importMetadata.getClassName());
} }
@Autowired(required=false) @Autowired(required = false)
void setConfigurers(Collection<TransactionManagementConfigurer> configurers) { void setConfigurers(Collection<TransactionManagementConfigurer> configurers) {
if (CollectionUtils.isEmpty(configurers)) { if (CollectionUtils.isEmpty(configurers)) {
return; return;

33
spring-tx/src/main/java/org/springframework/transaction/annotation/TransactionManagementConfigurer.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,18 +21,20 @@ import org.springframework.transaction.PlatformTransactionManager;
/** /**
* Interface to be implemented by @{@link org.springframework.context.annotation.Configuration * Interface to be implemented by @{@link org.springframework.context.annotation.Configuration
* Configuration} classes annotated with @{@link EnableTransactionManagement} that wish to * Configuration} classes annotated with @{@link EnableTransactionManagement} that wish to
* or need to explicitly specify the default {@link PlatformTransactionManager} bean to be used * or need to explicitly specify the default {@link PlatformTransactionManager} bean to be
* for annotation-driven transaction management, as opposed to the default approach of a * used for annotation-driven transaction management, as opposed to the default approach
* by-type lookup. One reason this might be necessary is if there are two * of a by-type lookup. One reason this might be necessary is if there are two
* {@code PlatformTransactionManager} beans present in the container. * {@code PlatformTransactionManager} beans present in the container.
* *
* <p>See @{@link EnableTransactionManagement} for general examples and context; see * <p>See @{@link EnableTransactionManagement} for general examples and context;
* {@link #annotationDrivenTransactionManager()} for detailed instructions. * see {@link #annotationDrivenTransactionManager()} for detailed instructions.
* *
* <p>Note that in by-type lookup disambiguation cases, an alternative approach to * <p>Note that in by-type lookup disambiguation cases, an alternative approach to
* implementing this interface is to simply mark one of the offending {@code * implementing this interface is to simply mark one of the offending
* PlatformTransactionManager} {@code @Bean} methods as @{@link * {@code PlatformTransactionManager} {@code @Bean} methods as
* org.springframework.context.annotation.Primary Primary}. * @{@link org.springframework.context.annotation.Primary Primary}.
* This is even generally preferred since it doesn't lead to early initialization
* of the {@code PlatformTransactionManager} bean.
* *
* @author Chris Beams * @author Chris Beams
* @since 3.1 * @since 3.1
@ -44,7 +46,6 @@ public interface TransactionManagementConfigurer {
/** /**
* Return the default transaction manager bean to use for annotation-driven database * Return the default transaction manager bean to use for annotation-driven database
* transaction management, i.e. when processing {@code @Transactional} methods. * transaction management, i.e. when processing {@code @Transactional} methods.
*
* <p>There are two basic approaches to implementing this method: * <p>There are two basic approaches to implementing this method:
* <h3>1. Implement the method and annotate it with {@code @Bean}</h3> * <h3>1. Implement the method and annotate it with {@code @Bean}</h3>
* In this case, the implementing {@code @Configuration} class implements this method, * In this case, the implementing {@code @Configuration} class implements this method,
@ -68,15 +69,13 @@ public interface TransactionManagementConfigurer {
* public PlatformTransactionManager annotationDrivenTransactionManager() { * public PlatformTransactionManager annotationDrivenTransactionManager() {
* return txManager(); // reference the existing {@code @Bean} method above * return txManager(); // reference the existing {@code @Bean} method above
* }</pre> * }</pre>
* * If taking approach #2, be sure that <em>only one</em> of the methods is marked
* If taking approach #2, be sure that <em>only one</em> of the methods is marked with * with {@code @Bean}!
* {@code @Bean}!
*
* <p>In either scenario #1 or #2, it is important that the * <p>In either scenario #1 or #2, it is important that the
* {@code PlatformTransactionManager} instance is managed as a Spring bean within the * {@code PlatformTransactionManager} instance is managed as a Spring bean within the
* container as all {@code PlatformTransactionManager} implementations take * container as all {@code PlatformTransactionManager} implementations take advantage
* advantage of Spring lifecycle callbacks such as {@code InitializingBean} and {@code * of Spring lifecycle callbacks such as {@code InitializingBean} and
* BeanFactoryAware}. * {@code BeanFactoryAware}.
*/ */
PlatformTransactionManager annotationDrivenTransactionManager(); PlatformTransactionManager annotationDrivenTransactionManager();

Loading…
Cancel
Save