public class DefaultListableBeanFactory extends org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory implements org.springframework.beans.factory.config.ConfigurableListableBeanFactory, org.springframework.beans.factory.support.BeanDefinitionRegistry, Serializable
ListableBeanFactory and
BeanDefinitionRegistry interfaces: a full-fledged bean factory
based on bean definition objects.
Typical usage is registering all bean definitions first (possibly read from a bean definition file), before accessing beans. Bean definition lookup is therefore an inexpensive operation in a local bean definition table, operating on pre-built bean definition metadata objects.
Can be used as a standalone bean factory, or as a superclass for custom
bean factories. Note that readers for specific bean definition formats are
typically implemented separately rather than as bean factory subclasses:
see for example PropertiesBeanDefinitionReader and
XmlBeanDefinitionReader.
For an alternative implementation of the
ListableBeanFactory interface,
have a look at StaticListableBeanFactory, which manages existing
bean instances rather than creating new ones based on bean definitions.
RICE Implementation note: This class, copied from Spring 3.2.3 contains the fix contributed for performance problem related to large Spring configuration sets.
StaticListableBeanFactory,
PropertiesBeanDefinitionReader,
XmlBeanDefinitionReader,
Serialized Formlogger, NULL_OBJECTAUTOWIRE_AUTODETECT, AUTOWIRE_BY_NAME, AUTOWIRE_BY_TYPE, AUTOWIRE_CONSTRUCTOR, AUTOWIRE_NO| Constructor and Description |
|---|
DefaultListableBeanFactory()
Create a new DefaultListableBeanFactory.
|
DefaultListableBeanFactory(org.springframework.beans.factory.BeanFactory parentBeanFactory)
Create a new DefaultListableBeanFactory with the given parent.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addBeanToParentMap(String parentName,
String beanName) |
protected boolean |
allowAliasOverriding()
Only allows alias overriding if bean definition overriding is allowed.
|
boolean |
containsBeanDefinition(String beanName) |
void |
copyConfigurationFrom(org.springframework.beans.factory.config.ConfigurableBeanFactory otherFactory) |
void |
destroySingleton(String beanName) |
protected String |
determinePrimaryCandidate(Map<String,Object> candidateBeans,
org.springframework.beans.factory.config.DependencyDescriptor descriptor)
Determine the primary autowire candidate in the given set of beans.
|
protected Object |
doResolveDependency(org.springframework.beans.factory.config.DependencyDescriptor descriptor,
Class<?> type,
String beanName,
Set<String> autowiredBeanNames,
org.springframework.beans.TypeConverter typeConverter) |
<A extends Annotation> |
findAnnotationOnBean(String beanName,
Class<A> annotationType)
Find a
Annotation of annotationType on the specified
bean, traversing its interfaces and super classes if no annotation can be
found on the given class itself, as well as checking its raw bean class
if not found on the exposed bean reference (e.g. |
protected Map<String,Object> |
findAutowireCandidates(String beanName,
Class<?> requiredType,
org.springframework.beans.factory.config.DependencyDescriptor descriptor)
Find bean instances that match the required type.
|
void |
freezeConfiguration() |
org.springframework.beans.factory.support.AutowireCandidateResolver |
getAutowireCandidateResolver()
Return the autowire candidate resolver for this BeanFactory (never
null). |
<T> T |
getBean(Class<T> requiredType) |
org.springframework.beans.factory.config.BeanDefinition |
getBeanDefinition(String beanName) |
int |
getBeanDefinitionCount() |
String[] |
getBeanDefinitionNames() |
String[] |
getBeanNamesForType(Class<?> type) |
String[] |
getBeanNamesForType(Class<?> type,
boolean includeNonSingletons,
boolean allowEagerInit) |
<T> Map<String,T> |
getBeansOfType(Class<T> type) |
<T> Map<String,T> |
getBeansOfType(Class<T> type,
boolean includeNonSingletons,
boolean allowEagerInit) |
Map<String,Object> |
getBeansWithAnnotation(Class<? extends Annotation> annotationType) |
boolean |
isAutowireCandidate(String beanName,
org.springframework.beans.factory.config.DependencyDescriptor descriptor) |
protected boolean |
isAutowireCandidate(String beanName,
org.springframework.beans.factory.support.RootBeanDefinition mbd,
org.springframework.beans.factory.config.DependencyDescriptor descriptor)
Determine whether the specified bean definition qualifies as an autowire candidate,
to be injected into other beans which declare a dependency of matching type.
|
protected boolean |
isBeanEligibleForMetadataCaching(String beanName)
Considers all beans as eligible for metadata caching
if the factory's configuration has been marked as frozen.
|
boolean |
isConfigurationFrozen() |
protected boolean |
isPrimary(String beanName,
Object beanInstance)
Return whether the bean definition for the given bean name has been
marked as a primary bean.
|
protected boolean |
matchesBeanName(String beanName,
String candidateName)
Determine whether the given candidate name matches the bean name or the aliases
stored in this bean definition.
|
void |
preInstantiateSingletons() |
void |
registerBeanDefinition(String beanName,
org.springframework.beans.factory.config.BeanDefinition beanDefinition) |
void |
registerResolvableDependency(Class<?> dependencyType,
Object autowiredValue) |
void |
registerSingleton(String beanName,
Object singletonObject) |
void |
removeBeanDefinition(String beanName) |
protected void |
resetBeanDefinition(String beanName)
Reset all bean definition caches for the given bean,
including the caches of beans that are derived from it.
|
protected static Object |
resolveAutowiringValue(Object autowiringValue,
Class requiredType) |
Object |
resolveDependency(org.springframework.beans.factory.config.DependencyDescriptor descriptor,
String beanName,
Set<String> autowiredBeanNames,
org.springframework.beans.TypeConverter typeConverter) |
void |
setAllowBeanDefinitionOverriding(boolean allowBeanDefinitionOverriding)
Set whether it should be allowed to override bean definitions by registering
a different definition with the same name, automatically replacing the former.
|
void |
setAllowEagerClassLoading(boolean allowEagerClassLoading)
Set whether the factory is allowed to eagerly load bean classes
even for bean definitions that are marked as "lazy-init".
|
void |
setAutowireCandidateResolver(org.springframework.beans.factory.support.AutowireCandidateResolver autowireCandidateResolver)
Set a custom autowire candidate resolver for this BeanFactory to use
when deciding whether a bean definition should be considered as a
candidate for autowiring.
|
void |
setSerializationId(String serializationId)
Specify an id for serialization purposes, allowing this BeanFactory to be
deserialized from this id back into the BeanFactory object, if needed.
|
String |
toString() |
protected Object |
writeReplace() |
applyBeanPostProcessorsAfterInitialization, applyBeanPostProcessorsBeforeInitialization, applyBeanPostProcessorsBeforeInstantiation, applyBeanPropertyValues, applyMergedBeanDefinitionPostProcessors, applyPropertyValues, autowire, autowireBean, autowireBeanProperties, autowireByName, autowireByType, autowireConstructor, checkDependencies, configureBean, createBean, createBean, createBean, createBeanInstance, determineConstructorsFromBeanPostProcessors, doCreateBean, filterPropertyDescriptorsForDependencyCheck, filterPropertyDescriptorsForDependencyCheck, getEarlyBeanReference, getInstantiationStrategy, getParameterNameDiscoverer, getTypeForFactoryBean, getTypeForFactoryMethod, ignoreDependencyInterface, ignoreDependencyType, initializeBean, initializeBean, instantiateBean, instantiateUsingFactoryMethod, invokeCustomInitMethod, invokeInitMethods, isExcludedFromDependencyCheck, populateBean, postProcessObjectFromFactoryBean, predictBeanType, removeSingleton, resolveBeforeInstantiation, resolveDependency, setAllowCircularReferences, setAllowRawInjectionDespiteWrapping, setInstantiationStrategy, setParameterNameDiscoverer, unsatisfiedNonSimplePropertiesaddBeanPostProcessor, addEmbeddedValueResolver, addPropertyEditorRegistrar, afterPrototypeCreation, beforePrototypeCreation, checkMergedBeanDefinition, cleanupAfterBeanCreationFailure, clearMergedBeanDefinition, containsBean, containsLocalBean, copyRegisteredEditorsTo, destroyBean, destroyBean, destroyScopedBean, doGetBean, evaluateBeanDefinitionString, getAccessControlContext, getAliases, getBean, getBean, getBean, getBean, getBeanClassLoader, getBeanExpressionResolver, getBeanPostProcessorCount, getBeanPostProcessors, getConversionService, getCustomEditors, getCustomTypeConverter, getMergedBeanDefinition, getMergedBeanDefinition, getMergedBeanDefinition, getMergedLocalBeanDefinition, getObjectForBeanInstance, getParentBeanFactory, getPropertyEditorRegistrars, getRegisteredScope, getRegisteredScopeNames, getTempClassLoader, getType, getTypeConverter, hasDestructionAwareBeanPostProcessors, hasInstantiationAwareBeanPostProcessors, initBeanWrapper, isActuallyInCreation, isBeanNameInUse, isCacheBeanMetadata, isFactoryBean, isFactoryBean, isPrototype, isPrototypeCurrentlyInCreation, isSingleton, isTypeMatch, markBeanAsCreated, originalBeanName, registerCustomEditor, registerCustomEditors, registerDisposableBeanIfNecessary, registerScope, removeSingletonIfCreatedForTypeCheckOnly, requiresDestruction, resolveBeanClass, resolveEmbeddedValue, setBeanClassLoader, setBeanExpressionResolver, setCacheBeanMetadata, setConversionService, setParentBeanFactory, setSecurityContextProvider, setTempClassLoader, setTypeConverter, transformedBeanNamegetCachedObjectForFactoryBean, getFactoryBean, getObjectFromFactoryBean, getTypeForFactoryBeanaddSingleton, addSingletonFactory, afterSingletonCreation, beforeSingletonCreation, containsSingleton, destroyBean, destroySingletons, getDependenciesForBean, getDependentBeans, getSingleton, getSingleton, getSingleton, getSingletonCount, getSingletonMutex, getSingletonNames, hasDependentBean, isCurrentlyInCreation, isSingletonCurrentlyInCreation, onSuppressedException, registerContainedBean, registerDependentBean, registerDisposableBean, setCurrentlyInCreationcanonicalName, checkForAliasCircle, isAlias, registerAlias, removeAlias, resolveAliasesclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitignoreDependencyInterface, ignoreDependencyTypeapplyBeanPostProcessorsAfterInitialization, applyBeanPostProcessorsBeforeInitialization, applyBeanPropertyValues, autowire, autowireBean, autowireBeanProperties, configureBean, createBean, createBean, initializeBean, resolveDependencyaddBeanPostProcessor, addEmbeddedValueResolver, addPropertyEditorRegistrar, copyRegisteredEditorsTo, destroyBean, destroyScopedBean, destroySingletons, getAccessControlContext, getBeanClassLoader, getBeanExpressionResolver, getBeanPostProcessorCount, getConversionService, getDependenciesForBean, getDependentBeans, getMergedBeanDefinition, getRegisteredScope, getRegisteredScopeNames, getTempClassLoader, getTypeConverter, isCacheBeanMetadata, isCurrentlyInCreation, isFactoryBean, registerAlias, registerCustomEditor, registerDependentBean, registerScope, resolveAliases, resolveEmbeddedValue, setBeanClassLoader, setBeanExpressionResolver, setCacheBeanMetadata, setConversionService, setCurrentlyInCreation, setParentBeanFactory, setTempClassLoader, setTypeConvertercontainsLocalBean, getParentBeanFactorycontainsBean, getAliases, getBean, getBean, getBean, getType, isPrototype, isSingleton, isTypeMatchcontainsSingleton, getSingleton, getSingletonCount, getSingletonNamespublic DefaultListableBeanFactory()
public DefaultListableBeanFactory(org.springframework.beans.factory.BeanFactory parentBeanFactory)
parentBeanFactory - the parent BeanFactorypublic void setSerializationId(String serializationId)
public void setAllowBeanDefinitionOverriding(boolean allowBeanDefinitionOverriding)
Default is "true".
public void setAllowEagerClassLoading(boolean allowEagerClassLoading)
Default is "true". Turn this flag off to suppress class loading for lazy-init beans unless such a bean is explicitly requested. In particular, by-type lookups will then simply ignore bean definitions without resolved class name, instead of loading the bean classes on demand just to perform a type check.
AbstractBeanDefinition.setLazyInit(boolean)public void setAutowireCandidateResolver(org.springframework.beans.factory.support.AutowireCandidateResolver autowireCandidateResolver)
public org.springframework.beans.factory.support.AutowireCandidateResolver getAutowireCandidateResolver()
null).public void copyConfigurationFrom(org.springframework.beans.factory.config.ConfigurableBeanFactory otherFactory)
copyConfigurationFrom in interface org.springframework.beans.factory.config.ConfigurableBeanFactorycopyConfigurationFrom in class org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactorypublic <T> T getBean(Class<T> requiredType) throws org.springframework.beans.BeansException
getBean in interface org.springframework.beans.factory.BeanFactoryorg.springframework.beans.BeansExceptionpublic boolean containsBeanDefinition(String beanName)
containsBeanDefinition in interface org.springframework.beans.factory.ListableBeanFactorycontainsBeanDefinition in interface org.springframework.beans.factory.support.BeanDefinitionRegistrycontainsBeanDefinition in class org.springframework.beans.factory.support.AbstractBeanFactorypublic int getBeanDefinitionCount()
getBeanDefinitionCount in interface org.springframework.beans.factory.ListableBeanFactorygetBeanDefinitionCount in interface org.springframework.beans.factory.support.BeanDefinitionRegistrypublic String[] getBeanDefinitionNames()
getBeanDefinitionNames in interface org.springframework.beans.factory.ListableBeanFactorygetBeanDefinitionNames in interface org.springframework.beans.factory.support.BeanDefinitionRegistrypublic String[] getBeanNamesForType(Class<?> type)
getBeanNamesForType in interface org.springframework.beans.factory.ListableBeanFactorypublic String[] getBeanNamesForType(Class<?> type, boolean includeNonSingletons, boolean allowEagerInit)
getBeanNamesForType in interface org.springframework.beans.factory.ListableBeanFactorypublic <T> Map<String,T> getBeansOfType(Class<T> type) throws org.springframework.beans.BeansException
getBeansOfType in interface org.springframework.beans.factory.ListableBeanFactoryorg.springframework.beans.BeansExceptionpublic <T> Map<String,T> getBeansOfType(Class<T> type, boolean includeNonSingletons, boolean allowEagerInit) throws org.springframework.beans.BeansException
getBeansOfType in interface org.springframework.beans.factory.ListableBeanFactoryorg.springframework.beans.BeansExceptionpublic Map<String,Object> getBeansWithAnnotation(Class<? extends Annotation> annotationType)
getBeansWithAnnotation in interface org.springframework.beans.factory.ListableBeanFactorypublic <A extends Annotation> A findAnnotationOnBean(String beanName, Class<A> annotationType)
Annotation of annotationType on the specified
bean, traversing its interfaces and super classes if no annotation can be
found on the given class itself, as well as checking its raw bean class
if not found on the exposed bean reference (e.g. in case of a proxy).findAnnotationOnBean in interface org.springframework.beans.factory.ListableBeanFactorypublic void registerResolvableDependency(Class<?> dependencyType, Object autowiredValue)
registerResolvableDependency in interface org.springframework.beans.factory.config.ConfigurableListableBeanFactorypublic boolean isAutowireCandidate(String beanName, org.springframework.beans.factory.config.DependencyDescriptor descriptor) throws org.springframework.beans.factory.NoSuchBeanDefinitionException
isAutowireCandidate in interface org.springframework.beans.factory.config.ConfigurableListableBeanFactoryorg.springframework.beans.factory.NoSuchBeanDefinitionExceptionprotected boolean isAutowireCandidate(String beanName, org.springframework.beans.factory.support.RootBeanDefinition mbd, org.springframework.beans.factory.config.DependencyDescriptor descriptor)
beanName - the name of the bean definition to checkmbd - the merged bean definition to checkdescriptor - the descriptor of the dependency to resolvepublic org.springframework.beans.factory.config.BeanDefinition getBeanDefinition(String beanName) throws org.springframework.beans.factory.NoSuchBeanDefinitionException
getBeanDefinition in interface org.springframework.beans.factory.config.ConfigurableListableBeanFactorygetBeanDefinition in interface org.springframework.beans.factory.support.BeanDefinitionRegistrygetBeanDefinition in class org.springframework.beans.factory.support.AbstractBeanFactoryorg.springframework.beans.factory.NoSuchBeanDefinitionExceptionpublic void freezeConfiguration()
freezeConfiguration in interface org.springframework.beans.factory.config.ConfigurableListableBeanFactorypublic boolean isConfigurationFrozen()
isConfigurationFrozen in interface org.springframework.beans.factory.config.ConfigurableListableBeanFactoryprotected boolean isBeanEligibleForMetadataCaching(String beanName)
isBeanEligibleForMetadataCaching in class org.springframework.beans.factory.support.AbstractBeanFactoryfreezeConfiguration()public void preInstantiateSingletons() throws org.springframework.beans.BeansException
preInstantiateSingletons in interface org.springframework.beans.factory.config.ConfigurableListableBeanFactoryorg.springframework.beans.BeansExceptionpublic void registerBeanDefinition(String beanName, org.springframework.beans.factory.config.BeanDefinition beanDefinition) throws org.springframework.beans.factory.BeanDefinitionStoreException
registerBeanDefinition in interface org.springframework.beans.factory.support.BeanDefinitionRegistryorg.springframework.beans.factory.BeanDefinitionStoreExceptionpublic void removeBeanDefinition(String beanName) throws org.springframework.beans.factory.NoSuchBeanDefinitionException
removeBeanDefinition in interface org.springframework.beans.factory.support.BeanDefinitionRegistryorg.springframework.beans.factory.NoSuchBeanDefinitionExceptionprotected void resetBeanDefinition(String beanName)
beanName - the name of the bean to resetprotected void addBeanToParentMap(String parentName, String beanName)
protected boolean allowAliasOverriding()
allowAliasOverriding in class org.springframework.core.SimpleAliasRegistrypublic void registerSingleton(String beanName, Object singletonObject) throws IllegalStateException
registerSingleton in interface org.springframework.beans.factory.config.SingletonBeanRegistryregisterSingleton in class org.springframework.beans.factory.support.DefaultSingletonBeanRegistryIllegalStateExceptionpublic void destroySingleton(String beanName)
destroySingleton in class org.springframework.beans.factory.support.DefaultSingletonBeanRegistrypublic Object resolveDependency(org.springframework.beans.factory.config.DependencyDescriptor descriptor, String beanName, Set<String> autowiredBeanNames, org.springframework.beans.TypeConverter typeConverter) throws org.springframework.beans.BeansException
resolveDependency in interface org.springframework.beans.factory.config.AutowireCapableBeanFactoryorg.springframework.beans.BeansExceptionprotected Object doResolveDependency(org.springframework.beans.factory.config.DependencyDescriptor descriptor, Class<?> type, String beanName, Set<String> autowiredBeanNames, org.springframework.beans.TypeConverter typeConverter) throws org.springframework.beans.BeansException
org.springframework.beans.BeansExceptionprotected Map<String,Object> findAutowireCandidates(String beanName, Class<?> requiredType, org.springframework.beans.factory.config.DependencyDescriptor descriptor)
beanName - the name of the bean that is about to be wiredrequiredType - the actual type of bean to look for
(may be an array component type or collection element type)descriptor - the descriptor of the dependency to resolvenull)org.springframework.beans.BeansException - in case of errorsAbstractAutowireCapableBeanFactory.autowireByType(java.lang.String, org.springframework.beans.factory.support.AbstractBeanDefinition, org.springframework.beans.BeanWrapper, org.springframework.beans.MutablePropertyValues),
AbstractAutowireCapableBeanFactory.autowireConstructor(java.lang.String, org.springframework.beans.factory.support.RootBeanDefinition, java.lang.reflect.Constructor<?>[], java.lang.Object[])protected static Object resolveAutowiringValue(Object autowiringValue, Class requiredType)
protected String determinePrimaryCandidate(Map<String,Object> candidateBeans, org.springframework.beans.factory.config.DependencyDescriptor descriptor)
candidateBeans - a Map of candidate names and candidate instances
that match the required type, as returned by findAutowireCandidates(java.lang.String, java.lang.Class<?>, org.springframework.beans.factory.config.DependencyDescriptor)descriptor - the target dependency to match againstnull if none foundprotected boolean isPrimary(String beanName, Object beanInstance)
beanName - the name of the beanbeanInstance - the corresponding bean instanceprotected boolean matchesBeanName(String beanName, String candidateName)
protected Object writeReplace() throws ObjectStreamException
ObjectStreamExceptionCopyright © 2005–2016 The Kuali Foundation. All rights reserved.