Skip to content

Commit 02374d7

Browse files
committed
TransactionAspectSupport avoids hard references to transaction manager beans
Issue: SPR-14511
1 parent b9ab895 commit 02374d7

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.lang.reflect.Method;
2020
import java.util.Properties;
21-
import java.util.concurrent.ConcurrentHashMap;
2221
import java.util.concurrent.ConcurrentMap;
2322

2423
import org.apache.commons.logging.Log;
@@ -35,6 +34,7 @@
3534
import org.springframework.transaction.TransactionSystemException;
3635
import org.springframework.transaction.support.CallbackPreferringPlatformTransactionManager;
3736
import org.springframework.transaction.support.TransactionCallback;
37+
import org.springframework.util.ConcurrentReferenceHashMap;
3838
import org.springframework.util.StringUtils;
3939

4040
/**
@@ -68,13 +68,14 @@
6868
*/
6969
public abstract class TransactionAspectSupport implements BeanFactoryAware, InitializingBean {
7070

71+
// NOTE: This class must not implement Serializable because it serves as base
72+
// class for AspectJ aspects (which are not allowed to implement Serializable)!
73+
74+
7175
/**
7276
* Key to use to store the default transaction manager.
7377
*/
74-
private final Object DEFAULT_TRANSACTION_MANAGER_KEY = new Object();
75-
76-
// NOTE: This class must not implement Serializable because it serves as base
77-
// class for AspectJ aspects (which are not allowed to implement Serializable)!
78+
private static final Object DEFAULT_TRANSACTION_MANAGER_KEY = new Object();
7879

7980
/**
8081
* Holder to support the {@code currentTransactionStatus()} method,
@@ -86,9 +87,6 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
8687
new NamedThreadLocal<>("Current aspect-driven transaction");
8788

8889

89-
private final ConcurrentMap<Object, PlatformTransactionManager> transactionManagerCache =
90-
new ConcurrentHashMap<>();
91-
9290
/**
9391
* Subclasses can use this to return the current TransactionInfo.
9492
* Only subclasses that cannot handle all operations in one method,
@@ -128,15 +126,15 @@ public static TransactionStatus currentTransactionStatus() throws NoTransactionE
128126

129127
protected final Log logger = LogFactory.getLog(getClass());
130128

131-
/**
132-
* Default transaction manager bean name.
133-
*/
134129
private String transactionManagerBeanName;
135130

136131
private TransactionAttributeSource transactionAttributeSource;
137132

138133
private BeanFactory beanFactory;
139134

135+
private final ConcurrentMap<Object, PlatformTransactionManager> transactionManagerCache =
136+
new ConcurrentReferenceHashMap<>(4);
137+
140138

141139
/**
142140
* Specify the name of the default transaction manager bean.

0 commit comments

Comments
 (0)