From 67176e2b75d0b45ec609dcec161a4ddd05eafc6f Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 26 Jul 2016 21:29:34 +0200 Subject: [PATCH] TransactionAspectSupport avoids hard references to transaction manager beans Issue: SPR-14511 (cherry picked from commit 02374d7) --- .../interceptor/TransactionAspectSupport.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java b/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java index 69983842b65..7f196227ab9 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java +++ b/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java @@ -18,7 +18,6 @@ package org.springframework.transaction.interceptor; import java.lang.reflect.Method; import java.util.Properties; -import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import org.apache.commons.logging.Log; @@ -35,6 +34,7 @@ import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.TransactionSystemException; import org.springframework.transaction.support.CallbackPreferringPlatformTransactionManager; import org.springframework.transaction.support.TransactionCallback; +import org.springframework.util.ConcurrentReferenceHashMap; import org.springframework.util.StringUtils; /** @@ -68,13 +68,14 @@ import org.springframework.util.StringUtils; */ public abstract class TransactionAspectSupport implements BeanFactoryAware, InitializingBean { + // NOTE: This class must not implement Serializable because it serves as base + // class for AspectJ aspects (which are not allowed to implement Serializable)! + + /** * Key to use to store the default transaction manager. */ - private final Object DEFAULT_TRANSACTION_MANAGER_KEY = new Object(); - - // NOTE: This class must not implement Serializable because it serves as base - // class for AspectJ aspects (which are not allowed to implement Serializable)! + private static final Object DEFAULT_TRANSACTION_MANAGER_KEY = new Object(); /** * Holder to support the {@code currentTransactionStatus()} method, @@ -86,9 +87,6 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init new NamedThreadLocal("Current aspect-driven transaction"); - private final ConcurrentMap transactionManagerCache = - new ConcurrentHashMap(); - /** * Subclasses can use this to return the current TransactionInfo. * Only subclasses that cannot handle all operations in one method, @@ -128,15 +126,15 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init protected final Log logger = LogFactory.getLog(getClass()); - /** - * Default transaction manager bean name. - */ private String transactionManagerBeanName; private TransactionAttributeSource transactionAttributeSource; private BeanFactory beanFactory; + private final ConcurrentMap transactionManagerCache = + new ConcurrentReferenceHashMap(4); + /** * Specify the name of the default transaction manager bean.