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 git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4650 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
parent
e4c1be808f
commit
f5be4b22bb
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue