|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.beans.factory.BeanFactoryUtils
public abstract class BeanFactoryUtils
Convenience methods operating on bean factories, in particular on the ListableBeanFactory interface.
Returns bean counts, bean names or bean instances, taking into account the nesting hierarchy of a bean factory (which the methods defined on the ListableBeanFactory interface don't, in contrast to the methods defined on the BeanFactory interface).
Constructor Summary | |
---|---|
BeanFactoryUtils()
|
Method Summary | |
---|---|
static String[] |
beanNamesForTypeIncludingAncestors(ListableBeanFactory lbf,
Class type)
Get all bean names for the given type, including those defined in ancestor factories. |
static String[] |
beanNamesForTypeIncludingAncestors(ListableBeanFactory lbf,
Class type,
boolean includePrototypes,
boolean includeFactoryBeans)
Get all bean names for the given type, including those defined in ancestor factories. |
static String[] |
beanNamesIncludingAncestors(ListableBeanFactory lbf)
Return all bean names in the factory, including ancestor factories. |
static String[] |
beanNamesIncludingAncestors(ListableBeanFactory lbf,
Class type)
Deprecated. in favor of beanNamesForTypeIncludingAncestors. This method will be removed as of Spring 2.0. |
static Object |
beanOfType(ListableBeanFactory lbf,
Class type)
Return a single bean of the given type or subtypes, not looking in ancestor factories. |
static Object |
beanOfType(ListableBeanFactory lbf,
Class type,
boolean includePrototypes,
boolean includeFactoryBeans)
Return a single bean of the given type or subtypes, not looking in ancestor factories. |
static Object |
beanOfTypeIncludingAncestors(ListableBeanFactory lbf,
Class type)
Return a single bean of the given type or subtypes, also picking up beans defined in ancestor bean factories if the current bean factory is a HierarchicalBeanFactory. |
static Object |
beanOfTypeIncludingAncestors(ListableBeanFactory lbf,
Class type,
boolean includePrototypes,
boolean includeFactoryBeans)
Return a single bean of the given type or subtypes, also picking up beans defined in ancestor bean factories if the current bean factory is a HierarchicalBeanFactory. |
static Map |
beansOfTypeIncludingAncestors(ListableBeanFactory lbf,
Class type)
Return all beans of the given type or subtypes, also picking up beans defined in ancestor bean factories if the current bean factory is a HierarchicalBeanFactory. |
static Map |
beansOfTypeIncludingAncestors(ListableBeanFactory lbf,
Class type,
boolean includePrototypes,
boolean includeFactoryBeans)
Return all beans of the given type or subtypes, also picking up beans defined in ancestor bean factories if the current bean factory is a HierarchicalBeanFactory. |
static int |
countBeansIncludingAncestors(ListableBeanFactory lbf)
Count all bean definitions in any hierarchy in which this factory participates. |
static boolean |
isFactoryDereference(String name)
Return whether the given name is a factory dereference (beginning with the factory dereference prefix). |
static String |
transformedBeanName(String name)
Return the bean name, stripping out the factory dereference prefix if necessary. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public BeanFactoryUtils()
Method Detail |
---|
public static boolean isFactoryDereference(String name)
BeanFactory.FACTORY_BEAN_PREFIX
public static String transformedBeanName(String name)
public static int countBeansIncludingAncestors(ListableBeanFactory lbf)
Beans that are "overridden" (specified in a descendant factory with the same name) are only counted once.
lbf
- the bean factory
public static String[] beanNamesIncludingAncestors(ListableBeanFactory lbf)
lbf
- the bean factory
public static String[] beanNamesIncludingAncestors(ListableBeanFactory lbf, Class type)
Does not consider objects created by FactoryBeans but rather the
FactoryBean classes themselves, avoiding instantiation of any beans. Use
beanNamesForTypeIncludingAncestors
to match objects created by
FactoryBeans.
lbf
- the bean factorytype
- the type that beans must match
beanNamesForTypeIncludingAncestors(org.springframework.beans.factory.ListableBeanFactory, java.lang.Class)
public static String[] beanNamesForTypeIncludingAncestors(ListableBeanFactory lbf, Class type)
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.
This version of beanNamesForTypeIncludingAncestors
automatically
includes prototypes and FactoryBeans.
lbf
- the bean factorytype
- the type that beans must match
public static String[] beanNamesForTypeIncludingAncestors(ListableBeanFactory lbf, Class type, boolean includePrototypes, boolean includeFactoryBeans)
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).
lbf
- the bean factoryincludePrototypes
- 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).type
- the type that beans must match
public static Map beansOfTypeIncludingAncestors(ListableBeanFactory lbf, Class type) throws BeansException
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.
lbf
- the bean factorytype
- type of bean to match
BeansException
- if a bean could not be createdpublic static Map beansOfTypeIncludingAncestors(ListableBeanFactory lbf, Class type, boolean includePrototypes, boolean includeFactoryBeans) throws BeansException
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).
lbf
- the bean factorytype
- type of bean to matchincludePrototypes
- 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).
BeansException
- if a bean could not be createdpublic static Object beanOfTypeIncludingAncestors(ListableBeanFactory lbf, Class type) throws BeansException
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.
This version of beanOfTypeIncludingAncestors
automatically includes
prototypes and FactoryBeans.
lbf
- the bean factorytype
- type of bean to match
NoSuchBeanDefinitionException
- if 0 or more than 1 beans of the given type were found
NoSuchBeanDefinitionException
- if no single bean could be found for the given type
BeansException
- if the bean could not be createdpublic static Object beanOfTypeIncludingAncestors(ListableBeanFactory lbf, Class type, boolean includePrototypes, boolean includeFactoryBeans) throws BeansException
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).
lbf
- the bean factorytype
- type of bean to matchincludePrototypes
- 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).
NoSuchBeanDefinitionException
- if 0 or more than 1 beans of the given type were found
NoSuchBeanDefinitionException
- if no single bean could be found for the given type
BeansException
- if the bean could not be createdpublic static Object beanOfType(ListableBeanFactory lbf, Class type) throws BeansException
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.
This version of beanOfType
automatically includes
prototypes and FactoryBeans.
lbf
- the bean factorytype
- type of bean to match
NoSuchBeanDefinitionException
- if 0 or more than 1 beans of the given type were found
NoSuchBeanDefinitionException
- if no single bean could be found for the given type
BeansException
- if the bean could not be createdpublic static Object beanOfType(ListableBeanFactory lbf, Class type, boolean includePrototypes, boolean includeFactoryBeans) throws BeansException
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).
lbf
- the bean factorytype
- type of bean to matchincludePrototypes
- 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).
NoSuchBeanDefinitionException
- if 0 or more than 1 beans of the given type were found
NoSuchBeanDefinitionException
- if no single bean could be found for the given type
BeansException
- if the bean could not be created
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |