org.springframework.beans.factory
Interface ListableBeanFactory

All Superinterfaces:
BeanFactory
All Known Subinterfaces:
ApplicationContext, ConfigurableApplicationContext, ConfigurableListableBeanFactory, ConfigurableWebApplicationContext, WebApplicationContext
All Known Implementing Classes:
AbstractApplicationContext, AbstractRefreshableApplicationContext, AbstractRefreshableWebApplicationContext, AbstractXmlApplicationContext, ClassPathXmlApplicationContext, DefaultListableBeanFactory, FileSystemXmlApplicationContext, GenericApplicationContext, GenericWebApplicationContext, StaticApplicationContext, StaticListableBeanFactory, StaticWebApplicationContext, XmlBeanFactory, XmlWebApplicationContext

public interface ListableBeanFactory
extends BeanFactory

Extension of the BeanFactory interface to be implemented by bean factories that can enumerate all their bean instances, rather than attempting bean lookup by name one by one as requested by clients. BeanFactory implementations that preload all their beans (for example, DOM-based XML factories) may implement this interface. This interface is discussed in "Expert One-on-One J2EE Design and Development", by Rod Johnson.

If this is a HierarchicalBeanFactory, the return values will not take any BeanFactory hierarchy into account, but will relate only to the beans defined in the current factory. Use the BeanFactoryUtils helper class to consider beans in ancestor factories too.

The methods in this interface will just respect bean definitions of this factory. They will ignore any singleton beans that have been registered by other means like ConfigurableBeanFactory's registerSingleton method, with the exception of getBeansOfType which will match such manually registered singletons too. Of course, BeanFactory's methods do allow access to such special beans too. In typical scenarios, all beans will be defined by bean definitions anyway.

With the exception of getBeanDefinitionCount and containsBeanDefinition, the methods in this interface are not designed for frequent invocation. Implementations may be slow.

Since:
16 April 2001
Author:
Rod Johnson, Juergen Hoeller
See Also:
HierarchicalBeanFactory, BeanFactoryUtils, ConfigurableBeanFactory.registerSingleton(java.lang.String, java.lang.Object)

Field Summary
 
Fields inherited from interface org.springframework.beans.factory.BeanFactory
FACTORY_BEAN_PREFIX
 
Method Summary
 boolean containsBeanDefinition(String beanName)
          Check if this bean factory contains a bean definition with the given name.
 int getBeanDefinitionCount()
          Return the number of beans defined in the factory.
 String[] getBeanDefinitionNames()
          Return the names of all beans defined in this factory.
 String[] getBeanDefinitionNames(Class type)
          Deprecated. in favor of getBeanNamesForType. This method will be removed as of Spring 1.3.
 String[] getBeanNamesForType(Class type)
          Return the names of beans matching the given type (including subclasses), judging from either bean definitions or the value of getObjectType in the case of FactoryBeans.
 String[] getBeanNamesForType(Class type, boolean includePrototypes, boolean includeFactoryBeans)
          Return the names of beans matching the given type (including subclasses), judging from either bean definitions or the value of getObjectType in the case of FactoryBeans.
 Map getBeansOfType(Class type)
          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.
 Map getBeansOfType(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.
 
Methods inherited from interface org.springframework.beans.factory.BeanFactory
containsBean, getAliases, getBean, getBean, getType, isSingleton
 

Method Detail

containsBeanDefinition

boolean containsBeanDefinition(String beanName)
Check if this bean factory contains a bean definition with the given name.

Does not consider any hierarchy this factory may participate in. Use containsBean to check ancestor factories too.

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

Parameters:
beanName - the name of the bean to look for
Returns:
if this bean factory contains a bean definition with the given name
See Also:
BeanFactory.containsBean(java.lang.String)

getBeanDefinitionCount

int getBeanDefinitionCount()
Return the number of beans defined in the factory.

Does not consider any hierarchy this factory may participate in. Use BeanFactoryUtils' countBeansIncludingAncestors to include beans in ancestor factories too.

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

Returns:
the number of beans defined in the factory
See Also:
BeanFactoryUtils.countBeansIncludingAncestors(org.springframework.beans.factory.ListableBeanFactory)

getBeanDefinitionNames

String[] getBeanDefinitionNames()
Return the names of all beans defined in this factory.

Does not consider any hierarchy this factory may participate in. Use BeanFactoryUtils' beanNamesIncludingAncestors to include beans in ancestor factories too.

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

Returns:
the names of all beans defined in this factory, or an empty array if none defined
See Also:
BeanFactoryUtils.beanNamesIncludingAncestors(ListableBeanFactory)

getBeanDefinitionNames

String[] getBeanDefinitionNames(Class type)
Deprecated. in favor of getBeanNamesForType. This method will be removed as of Spring 1.3.

Return the names of beans matching the given type (including subclasses), judging from the bean definitions. Merges child bean definition with their parent before checking the type.

Does not consider objects created by FactoryBeans but rather the FactoryBean classes themselves, avoiding instantiation of any beans. Use getBeanNamesForType to match objects created by FactoryBeans.

Does not consider any hierarchy this factory may participate in. Use BeanFactoryUtils' beanNamesIncludingAncestors to include beans in ancestor factories too.

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

Parameters:
type - the 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
See Also:
getBeanNamesForType(java.lang.Class), BeanFactoryUtils.beanNamesIncludingAncestors(ListableBeanFactory, Class)

getBeanNamesForType

String[] getBeanNamesForType(Class type)
Return the names of beans matching the given type (including subclasses), judging from either bean definitions or the value of getObjectType in the case of FactoryBeans.

Does consider objects created by FactoryBeans, which means that FactoryBeans will get initialized. If the object created by the FactoryBean doesn't match, the raw FactoryBean itself will be matched against the type.

Does not consider any hierarchy this factory may participate in. Use BeanFactoryUtils' beanNamesForTypeIncludingAncestors to include beans in ancestor factories too.

Note: Does not ignore singleton beans that have been registered by other means than bean definitions.

This version of getBeanNamesForType matches all kinds of beans, be it singletons, prototypes, or FactoryBeans. In most implementations, the result will be the same as for getBeanNamesOfType(type, true, true).

Parameters:
type - the class or interface to match, or null for all bean names
Returns:
the names of beans (or objects created by FactoryBeans) matching the given object type (including subclasses), or an empty array if none
See Also:
FactoryBean.getObjectType(), BeanFactoryUtils.beanNamesForTypeIncludingAncestors(ListableBeanFactory, Class)

getBeanNamesForType

String[] getBeanNamesForType(Class type,
                             boolean includePrototypes,
                             boolean includeFactoryBeans)
Return the names of beans matching the given type (including subclasses), judging from either bean definitions or the value of getObjectType in the case of FactoryBeans.

Does consider objects created by FactoryBeans if the "includeFactoryBeans" flag is set, which means that FactoryBeans will get initialized. If the object created by the FactoryBean doesn't match, the raw FactoryBean itself will be matched against the type. If "includeFactoryBeans" is not set, only raw FactoryBeans will be checked (which doesn't require initialization of each FactoryBean). $ *

Does not consider any hierarchy this factory may participate in. Use BeanFactoryUtils' beanNamesForTypeIncludingAncestors to include beans in ancestor factories too.

Note: Does not ignore singleton beans that have been registered by other means than bean definitions.

Parameters:
type - the class or interface to match, or null for all bean names
includePrototypes - whether to include prototype beans too or just singletons (also applies to FactoryBeans)
includeFactoryBeans - whether to include objects created by FactoryBeans (or by factory methods with a "factory-bean" reference) too, or just conventional beans. Note that FactoryBeans need to be initialized to determine their type: So be aware that passing in "true" for this flag will initialize FactoryBeans (and "factory-bean" references).
Returns:
the names of beans (or objects created by FactoryBeans) matching the given object type (including subclasses), or an empty array if none
See Also:
FactoryBean.getObjectType(), BeanFactoryUtils.beanNamesForTypeIncludingAncestors(ListableBeanFactory, Class, boolean, boolean)

getBeansOfType

Map getBeansOfType(Class type)
                   throws BeansException
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 consider objects created by FactoryBeans, which means that FactoryBeans will get initialized. If the object created by the FactoryBean doesn't match, the raw FactoryBean itself will be matched against the type.

Does not consider any hierarchy this factory may participate in. Use BeanFactoryUtils' beansOfTypeIncludingAncestors to include beans in ancestor factories too.

Note: Does not ignore singleton beans that have been registered by other means than bean definitions.

This version of getBeansOfType matches all kinds of beans, be it singletons, prototypes, or FactoryBeans. In most implementations, the result will be the same as for getBeansOfType(type, true, true).

Parameters:
type - the class or interface to match, or null for all concrete beans
Returns:
a Map with the matching beans, containing the bean names as keys and the corresponding bean instances as values
Throws:
BeansException - if a bean could not be created
Since:
1.1.2
See Also:
FactoryBean.getObjectType(), BeanFactoryUtils.beansOfTypeIncludingAncestors(ListableBeanFactory, Class)

getBeansOfType

Map getBeansOfType(Class type,
                   boolean includePrototypes,
                   boolean includeFactoryBeans)
                   throws BeansException
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 consider objects created by FactoryBeans if the "includeFactoryBeans" flag is set, which means that FactoryBeans will get initialized. If the object created by the FactoryBean doesn't match, the raw FactoryBean itself will be matched against the type. If "includeFactoryBeans" is not set, only raw FactoryBeans will be checked (which doesn't require initialization of each FactoryBean).

Does not consider any hierarchy this factory may participate in. Use BeanFactoryUtils' beansOfTypeIncludingAncestors to include beans in ancestor factories too.

Note: Does not ignore singleton beans that have been registered by other means than bean definitions.

Parameters:
type - the class or interface to match, or null for all concrete beans
includePrototypes - whether to include prototype beans too or just singletons (also applies to FactoryBeans)
includeFactoryBeans - whether to include objects created by FactoryBeans (or by factory methods with a "factory-bean" reference) too, or just conventional beans. Note that FactoryBeans need to be initialized to determine their type: So be aware that passing in "true" for this flag will initialize FactoryBeans (and "factory-bean" references).
Returns:
a Map with the matching beans, containing the bean names as keys and the corresponding bean instances as values
Throws:
BeansException - if a bean could not be created
See Also:
FactoryBean.getObjectType(), BeanFactoryUtils.beansOfTypeIncludingAncestors(ListableBeanFactory, Class, boolean, boolean)


Copyright (c) 2002-2005 The Spring Framework Project.