BeanFactoryUtils caches transformedBeanName results for factory beans
Issue: SPR-17151
This commit is contained in:
@@ -22,6 +22,7 @@ import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.core.ResolvableType;
|
||||
@@ -51,6 +52,13 @@ public abstract class BeanFactoryUtils {
|
||||
*/
|
||||
public static final String GENERATED_BEAN_NAME_SEPARATOR = "#";
|
||||
|
||||
/**
|
||||
* Cache from name with factory bean prefix to stripped name without dereference.
|
||||
* @since 5.1
|
||||
* @see BeanFactory#FACTORY_BEAN_PREFIX
|
||||
*/
|
||||
private static final Map<String, String> transformedBeanNameCache = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
* Return whether the given name is a factory dereference
|
||||
@@ -72,11 +80,16 @@ public abstract class BeanFactoryUtils {
|
||||
*/
|
||||
public static String transformedBeanName(String name) {
|
||||
Assert.notNull(name, "'name' must not be null");
|
||||
String beanName = name;
|
||||
while (beanName.startsWith(BeanFactory.FACTORY_BEAN_PREFIX)) {
|
||||
beanName = beanName.substring(BeanFactory.FACTORY_BEAN_PREFIX.length());
|
||||
if (!name.startsWith(BeanFactory.FACTORY_BEAN_PREFIX)) {
|
||||
return name;
|
||||
}
|
||||
return beanName;
|
||||
return transformedBeanNameCache.computeIfAbsent(name, beanName -> {
|
||||
do {
|
||||
beanName = beanName.substring(BeanFactory.FACTORY_BEAN_PREFIX.length());
|
||||
}
|
||||
while (beanName.startsWith(BeanFactory.FACTORY_BEAN_PREFIX));
|
||||
return beanName;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user