From 4262aed9c887e65c400a12434e42726b0fcb7fa4 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Sat, 2 Jul 2011 22:22:33 +0000 Subject: [PATCH] Refactor BeanFactoryLocator to use getBean(Class) Prior to this change, (Context)SingletonBeanFactoryLocator used BeanFactoryUtils#beanOfType(ListableBeanFactory, Class) to locate the bean of type BeanFactory. The more modern approach is to use BeanFactory#getBean(Class), which removes a dependency on ListableBeanFactory interface while at the same time opening the implementation up to respecting autowiring exclusions, primary metadata, etc. Issue: SPR-8489 --- .../factory/access/SingletonBeanFactoryLocator.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/access/SingletonBeanFactoryLocator.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/access/SingletonBeanFactoryLocator.java index 2bdc1e5e5b..8425921237 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/access/SingletonBeanFactoryLocator.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/access/SingletonBeanFactoryLocator.java @@ -22,13 +22,10 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - import org.springframework.beans.BeansException; import org.springframework.beans.FatalBeanException; import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.BeanFactory; -import org.springframework.beans.factory.BeanFactoryUtils; -import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory; @@ -396,12 +393,8 @@ public class SingletonBeanFactoryLocator implements BeanFactoryLocator { if (factoryKey != null) { beanFactory = bfg.definition.getBean(factoryKey, BeanFactory.class); } - else if (bfg.definition instanceof ListableBeanFactory) { - beanFactory = BeanFactoryUtils.beanOfType((ListableBeanFactory) bfg.definition, BeanFactory.class); - } else { - throw new IllegalStateException( - "Factory key is null, and underlying factory is not a ListableBeanFactory: " + bfg.definition); + beanFactory = bfg.definition.getBean(BeanFactory.class); } return new CountingBeanFactoryReference(beanFactory, bfg.definition); }