org.springframework.beans.factory.support
Class DefaultListableBeanFactory

java.lang.Object
  extended byorg.springframework.beans.factory.support.AbstractBeanFactory
      extended byorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
          extended byorg.springframework.beans.factory.support.DefaultListableBeanFactory
All Implemented Interfaces:
AutowireCapableBeanFactory, BeanDefinitionRegistry, BeanFactory, ConfigurableBeanFactory, ConfigurableListableBeanFactory, HierarchicalBeanFactory, ListableBeanFactory
Direct Known Subclasses:
XmlBeanFactory

public class DefaultListableBeanFactory
extends AbstractAutowireCapableBeanFactory
implements ConfigurableListableBeanFactory, BeanDefinitionRegistry

Concrete implementation of ListableBeanFactory. Can be used as a standalone bean factory, or as a superclass for custom bean factories.

Since:
16 April 2001
Version:
$Id: DefaultListableBeanFactory.java,v 1.20 2004/03/22 14:07:47 jhoeller Exp $
Author:
Rod Johnson, Juergen Hoeller

Field Summary
 
Fields inherited from class org.springframework.beans.factory.support.AbstractBeanFactory
FACTORY_BEAN_PREFIX, logger
 
Fields inherited from interface org.springframework.beans.factory.config.AutowireCapableBeanFactory
AUTOWIRE_AUTODETECT, AUTOWIRE_BY_NAME, AUTOWIRE_BY_TYPE, AUTOWIRE_CONSTRUCTOR
 
Constructor Summary
DefaultListableBeanFactory()
          Create a new DefaultListableBeanFactory.
DefaultListableBeanFactory(BeanFactory parentBeanFactory)
          Create a new DefaultListableBeanFactory with the given parent.
 
Method Summary
 boolean containsBeanDefinition(java.lang.String name)
          Check if this registry contains a bean definition with the given name.
protected  java.util.Map findMatchingBeans(java.lang.Class requiredType)
          Find bean instances that match the required type.
 BeanDefinition getBeanDefinition(java.lang.String beanName)
          Return the BeanDefinition for the given bean name.
 int getBeanDefinitionCount()
          Return the number of beans defined in the registry.
 java.lang.String[] getBeanDefinitionNames()
          Return the names of all beans defined in this registry.
 java.lang.String[] getBeanDefinitionNames(java.lang.Class type)
          Note that this method is slow.
 java.util.Map getBeansOfType(java.lang.Class type, boolean includePrototypes, boolean includeFactoryBeans)
          Return the bean instances that match the given object type (including subclasses), judging from either bean definitions or the value of getObjectType() in the case of FactoryBeans.
protected  java.lang.String[] getDependingBeanNames(java.lang.String beanName)
          Return the names of the beans that depend on the given bean.
 void preInstantiateSingletons()
          Ensure that all non-lazy-init singletons are instantiated, also considering FactoryBeans.
 void registerBeanDefinition(java.lang.String name, BeanDefinition beanDefinition)
          Register a new bean definition with this registry.
 void setAllowBeanDefinitionOverriding(boolean allowBeanDefinitionOverriding)
          Set if it should be allowed to override bean definitions by registering a different definition with the same name, automatically replacing the former.
 java.lang.String toString()
           
 
Methods inherited from class org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
applyBeanPostProcessorsAfterInitialization, applyBeanPostProcessorsBeforeInitialization, applyPropertyValues, autowire, autowireBeanProperties, autowireByName, autowireByType, autowireConstructor, createBean, dependencyCheck, destroyBean, destroySingletons, invokeCustomDestroyMethod, invokeInitMethods, populateBean, resolveManagedList, resolveManagedMap, resolveManagedSet, resolveReference, resolveValueIfNecessary, unsatisfiedObjectProperties
 
Methods inherited from class org.springframework.beans.factory.support.AbstractBeanFactory
addBeanPostProcessor, addSingleton, containsBean, destroySingleton, getAliases, getBean, getBean, getBeanPostProcessors, getCustomEditors, getIgnoredDependencyTypes, getMergedBeanDefinition, getMergedBeanDefinition, getObjectForSharedInstance, getParentBeanFactory, getSingletonNames, ignoreDependencyType, initBeanWrapper, isFactoryDereference, isSingleton, registerAlias, registerCustomEditor, registerSingleton, setParentBeanFactory, transformedBeanName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.springframework.beans.factory.BeanFactory
containsBean, getAliases, getBean, getBean, isSingleton
 
Methods inherited from interface org.springframework.beans.factory.config.ConfigurableBeanFactory
addBeanPostProcessor, destroySingletons, ignoreDependencyType, registerAlias, registerCustomEditor, registerSingleton, setParentBeanFactory
 
Methods inherited from interface org.springframework.beans.factory.HierarchicalBeanFactory
getParentBeanFactory
 
Methods inherited from interface org.springframework.beans.factory.config.AutowireCapableBeanFactory
applyBeanPostProcessorsAfterInitialization, applyBeanPostProcessorsBeforeInitialization, autowire, autowireBeanProperties
 
Methods inherited from interface org.springframework.beans.factory.support.BeanDefinitionRegistry
getAliases, registerAlias
 

Constructor Detail

DefaultListableBeanFactory

public DefaultListableBeanFactory()
Create a new DefaultListableBeanFactory.


DefaultListableBeanFactory

public DefaultListableBeanFactory(BeanFactory parentBeanFactory)
Create a new DefaultListableBeanFactory with the given parent.

Method Detail

setAllowBeanDefinitionOverriding

public void setAllowBeanDefinitionOverriding(boolean allowBeanDefinitionOverriding)
Set if it should be allowed to override bean definitions by registering a different definition with the same name, automatically replacing the former. If not, an exception will be thrown. Default is true.


getBeanDefinitionCount

public int getBeanDefinitionCount()
Description copied from interface: BeanDefinitionRegistry
Return the number of beans defined in the registry.

Specified by:
getBeanDefinitionCount in interface ListableBeanFactory
Returns:
the number of beans defined in the factory

getBeanDefinitionNames

public java.lang.String[] getBeanDefinitionNames()
Description copied from interface: BeanDefinitionRegistry
Return the names of all beans defined in this registry.

Specified by:
getBeanDefinitionNames in interface ListableBeanFactory
Returns:
the names of all beans defined in this factory, or an empty array if none defined

getBeanDefinitionNames

public java.lang.String[] getBeanDefinitionNames(java.lang.Class type)
Note that this method is slow. Don't invoke it too often: it's best used only in application initialization.

Specified by:
getBeanDefinitionNames in interface ListableBeanFactory
Parameters:
type - class or interface to match, or null for all bean names
Returns:
the names of beans matching the given object type (including subclasses), or an empty array if none

containsBeanDefinition

public boolean containsBeanDefinition(java.lang.String name)
Description copied from interface: BeanDefinitionRegistry
Check if this registry contains a bean definition with the given name.

Specified by:
containsBeanDefinition in interface ListableBeanFactory
Specified by:
containsBeanDefinition in class AbstractBeanFactory
Parameters:
name - the name of the bean to look for
Returns:
if this bean factory contains a bean definition with the given name
See Also:
AbstractBeanFactory.containsBean(java.lang.String)

getBeansOfType

public java.util.Map getBeansOfType(java.lang.Class type,
                                    boolean includePrototypes,
                                    boolean includeFactoryBeans)
                             throws BeansException
Description copied from interface: ListableBeanFactory
Return the bean instances that match the given object type (including subclasses), judging from either bean definitions or the value of getObjectType() in the case of FactoryBeans. Does not consider any hierarchy this factory may participate in.

If FactoryBean's getObjectType() returns null and the bean is a singleton, the type of the actually created objects should be evaluated. Prototypes without explicit object type specification should be ignored.

Note: Ignores any singleton beans that have been registered by other means than bean definitions.

Specified by:
getBeansOfType in interface ListableBeanFactory
Parameters:
type - class or interface to match
includePrototypes - whether to include prototype beans too or just singletons (also applies to FactoryBeans)
includeFactoryBeans - whether to include FactoryBeans too or just normal beans
Returns:
a Map with the matching beans, containing the bean names as keys and the corresponding bean instances as values
Throws:
BeansException - if the beans could not be created

preInstantiateSingletons

public void preInstantiateSingletons()
Description copied from interface: ConfigurableListableBeanFactory
Ensure that all non-lazy-init singletons are instantiated, also considering FactoryBeans. Typically invoked at the end of factory setup, if desired.

Specified by:
preInstantiateSingletons in interface ConfigurableListableBeanFactory

registerBeanDefinition

public void registerBeanDefinition(java.lang.String name,
                                   BeanDefinition beanDefinition)
                            throws BeanDefinitionStoreException
Description copied from interface: BeanDefinitionRegistry
Register a new bean definition with this registry. Must support RootBeanDefinition and ChildBeanDefinition.

Specified by:
registerBeanDefinition in interface BeanDefinitionRegistry
Parameters:
name - the name of the bean instance to register
beanDefinition - definition of the bean instance to register
Throws:
BeanDefinitionStoreException
See Also:
RootBeanDefinition, ChildBeanDefinition

getBeanDefinition

public BeanDefinition getBeanDefinition(java.lang.String beanName)
                                 throws BeansException
Description copied from interface: BeanDefinitionRegistry
Return the BeanDefinition for the given bean name.

Specified by:
getBeanDefinition in interface ConfigurableBeanFactory
Specified by:
getBeanDefinition in class AbstractBeanFactory
Parameters:
beanName - name of the bean to find a definition for
Returns:
the BeanDefinition for this prototype name. Must never return null.
Throws:
BeansException - in case of errors
See Also:
RootBeanDefinition, ChildBeanDefinition

getDependingBeanNames

protected java.lang.String[] getDependingBeanNames(java.lang.String beanName)
                                            throws BeansException
Description copied from class: AbstractAutowireCapableBeanFactory
Return the names of the beans that depend on the given bean. Called by destroyBean, to be able to destroy depending beans first.

Specified by:
getDependingBeanNames in class AbstractAutowireCapableBeanFactory
Parameters:
beanName - name of the bean to find depending beans for
Returns:
array of names of depending beans, or null if none
Throws:
BeansException - in case of errors
See Also:
AbstractAutowireCapableBeanFactory.destroyBean(java.lang.String, java.lang.Object)

findMatchingBeans

protected java.util.Map findMatchingBeans(java.lang.Class requiredType)
Description copied from class: AbstractAutowireCapableBeanFactory
Find bean instances that match the required type. Called by autowiring. If a subclass cannot obtain information about bean names by type, a corresponding exception should be thrown.

Specified by:
findMatchingBeans in class AbstractAutowireCapableBeanFactory
Parameters:
requiredType - the type of the beans to look up
Returns:
a Map of bean names and bean instances that match the required type, or null if none found
See Also:
AbstractAutowireCapableBeanFactory.autowireByType(java.lang.String, org.springframework.beans.factory.support.RootBeanDefinition, org.springframework.beans.BeanWrapper, org.springframework.beans.MutablePropertyValues), AbstractAutowireCapableBeanFactory.autowireConstructor(java.lang.String, org.springframework.beans.factory.support.RootBeanDefinition)

toString

public java.lang.String toString()


Copyright (C) 2003-2004 The Spring Framework Project.