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).
| Modifier and Type | Field and Description |
|---|---|
| public static final String | GENERATED_BEAN_NAME_SEPARATOR
Separator for generated bean names. |
| private static final Map | transformedBeanNameCache
Cache from name with factory bean prefix to stripped name without dereference. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public static String[] | Returns: the array of matching bean names, or an empty array if nonethe bean factory lbf, Class<? extends Annotation> the type of annotation to look for annotationType)Get all bean names whose |
| public static String[] | Returns: the array of matching bean names, or an empty array if nonethe bean factory lbf, ResolvableType the type that beans must match (as a type)ResolvableType)Get all bean names for the given type, including those defined in ancestor factories. |
| public static String[] | Returns: the array of matching bean names, or an empty array if nonethe bean factory lbf, ResolvableType the type that beans must match (as a type, boolean ResolvableType)whether to include prototype or scoped beans too
or just singletons (also applies to FactoryBeans) includeNonSingletons, boolean whether to initialize lazy-init singletons and
objects created by FactoryBeans (or by factory methods with a
"factory-bean" reference) for the type check. Note that FactoryBeans need to be
eagerly initialized to determine their type: So be aware that passing in "true"
for this flag will initialize FactoryBeans and "factory-bean" references. allowEagerInit)Get all bean names for the given type, including those defined in ancestor factories. |
| public static String[] | Returns: the array of matching bean names, or an empty array if nonethe bean factory lbf, Class<?> the type that beans must match (as a type)Class)Get all bean names for the given type, including those defined in ancestor factories. |
| public static String[] | Returns: the array of matching bean names, or an empty array if nonethe bean factory lbf, Class<?> the type that beans must match type, boolean whether to include prototype or scoped beans too
or just singletons (also applies to FactoryBeans) includeNonSingletons, boolean whether to initialize lazy-init singletons and
objects created by FactoryBeans (or by factory methods with a
"factory-bean" reference) for the type check. Note that FactoryBeans need to be
eagerly initialized to determine their type: So be aware that passing in "true"
for this flag will initialize FactoryBeans and "factory-bean" references. allowEagerInit)Get all bean names for the given type, including those defined in ancestor factories. |
| public static String[] | Returns: the array of matching bean names, or an empty array if nonethe bean factory lbf)Return all bean names in the factory, including ancestor factories. |
| public static <T> T | Returns: the matching bean instancethe bean factory lbf, Class<T> type of bean to match type)Return a single bean of the given type or subtypes, not looking in ancestor factories. |
| public static <T> T | Returns: the matching bean instancethe bean factory lbf, Class<T> type of bean to match type, boolean whether to include prototype or scoped beans too
or just singletons (also applies to FactoryBeans) includeNonSingletons, boolean whether to initialize lazy-init singletons and
objects created by FactoryBeans (or by factory methods with a
"factory-bean" reference) for the type check. Note that FactoryBeans need to be
eagerly initialized to determine their type: So be aware that passing in "true"
for this flag will initialize FactoryBeans and "factory-bean" references. allowEagerInit)Return a single bean of the given type or subtypes, not looking in ancestor factories. |
| public static <T> T | Returns: the matching bean instancethe bean factory lbf, Class<T> type of bean to match 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. |
| public static <T> T | Returns: the matching bean instancethe bean factory lbf, Class<T> type of bean to match type, boolean whether to include prototype or scoped beans too
or just singletons (also applies to FactoryBeans) includeNonSingletons, boolean whether to initialize lazy-init singletons and
objects created by FactoryBeans (or by factory methods with a
"factory-bean" reference) for the type check. Note that FactoryBeans need to be
eagerly initialized to determine their type: So be aware that passing in "true"
for this flag will initialize FactoryBeans and "factory-bean" references. allowEagerInit)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. |
| public static <T> Map | Returns: the Map of matching bean instances, or an empty Map if nonethe bean factory lbf, Class<T> type of bean to match 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. |
| public static <T> Map | Returns: the Map of matching bean instances, or an empty Map if nonethe bean factory lbf, Class<T> type of bean to match type, boolean whether to include prototype or scoped beans too
or just singletons (also applies to FactoryBeans) includeNonSingletons, boolean whether to initialize lazy-init singletons and
objects created by FactoryBeans (or by factory methods with a
"factory-bean" reference) for the type check. Note that FactoryBeans need to be
eagerly initialized to determine their type: So be aware that passing in "true"
for this flag will initialize FactoryBeans and "factory-bean" references. allowEagerInit)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. |
| public static int | Returns: count of beans including those defined in ancestor factoriesthe bean factory lbf)Count all beans in any hierarchy in which this factory participates. |
| public static boolean | Returns: whether the given name is a factory dereferencethe name of the bean name)Return whether the given name is a factory dereference (beginning with the factory dereference prefix). |
| public static boolean | Returns: whether the given name is a generated bean namethe name of the bean name)Return whether the given name is a bean name which has been generated by the default naming strategy (containing a "#..." part). |
| private static String[] | Returns: the merged result (possibly the local result as-is)the local bean name result result, String[] the parent bean name result (possibly empty) parentResult, HierarchicalBeanFactory the local bean factory hbf)Merge the given bean names result with the given parent result. |
| public static String | Returns: the raw bean namethe potentially generated bean name name)Extract the "raw" bean name from the given (potentially generated) bean name, excluding any "#..." suffixes which might have been added for uniqueness. |
| public static String | Returns: the transformed namethe name of the bean name)Return the actual bean name, stripping out the factory dereference prefix (if any, also stripping repeated factory prefixes if found). |
| private static <T> T | Returns: the unique bean instancetype of bean to match type, Map<String, T> all matching beans found matchingBeans)Extract a unique bean for the given type from the given Map of matching beans. |
| GENERATED_BEAN_NAME_SEPARATOR | back to summary |
|---|---|
| public static final String GENERATED_BEAN_NAME_SEPARATOR Separator for generated bean names. If a class name or parent name is not unique, "#1", "#2" etc will be appended, until the name becomes unique. | |
| transformedBeanNameCache | back to summary |
|---|---|
| private static final Map<String, String> transformedBeanNameCache Cache from name with factory bean prefix to stripped name without dereference.
| |
| BeanFactoryUtils | back to summary |
|---|---|
| public BeanFactoryUtils() | |
| beanNamesForAnnotationIncludingAncestors | back to summary |
|---|---|
| public static String[] beanNamesForAnnotationIncludingAncestors(ListableBeanFactory lbf, Class<? extends Annotation> annotationType) Get all bean names whose
| |
| beanNamesForTypeIncludingAncestors | back to summary |
|---|---|
| public static String[] beanNamesForTypeIncludingAncestors(ListableBeanFactory lbf, ResolvableType type) Get all bean names for the given type, including those defined in ancestor factories. Will return unique names in case of overridden bean definitions. 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 | back to summary |
|---|---|
| public static String[] beanNamesForTypeIncludingAncestors(ListableBeanFactory lbf, ResolvableType type, boolean includeNonSingletons, boolean allowEagerInit) Get all bean names for the given type, including those defined in ancestor factories. Will return unique names in case of overridden bean definitions. Does consider objects created by FactoryBeans if the "allowEagerInit" 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 "allowEagerInit" is not set, only raw FactoryBeans will be checked (which doesn't require initialization of each FactoryBean).
| |
| beanNamesForTypeIncludingAncestors | back to summary |
|---|---|
| public static String[] beanNamesForTypeIncludingAncestors(ListableBeanFactory lbf, Class<?> type) Get all bean names for the given type, including those defined in ancestor factories. Will return unique names in case of overridden bean definitions. 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 | back to summary |
|---|---|
| public static String[] beanNamesForTypeIncludingAncestors(ListableBeanFactory lbf, Class<?> type, boolean includeNonSingletons, boolean allowEagerInit) Get all bean names for the given type, including those defined in ancestor factories. Will return unique names in case of overridden bean definitions. Does consider objects created by FactoryBeans if the "allowEagerInit" 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 "allowEagerInit" is not set, only raw FactoryBeans will be checked (which doesn't require initialization of each FactoryBean).
| |
| beanNamesIncludingAncestors | back to summary |
|---|---|
| public static String[] beanNamesIncludingAncestors(ListableBeanFactory lbf) Return all bean names in the factory, including ancestor factories.
| |
| beanOfType | back to summary |
|---|---|
| public static <T> T beanOfType(ListableBeanFactory lbf, Class<T> type) throws BeansException Return a single bean of the given type or subtypes, not looking in ancestor factories. Useful convenience method when we expect a single bean and don't care about the bean name. 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 | back to summary |
|---|---|
| public static <T> T beanOfType(ListableBeanFactory lbf, Class<T> type, boolean includeNonSingletons, boolean allowEagerInit) throws BeansException Return a single bean of the given type or subtypes, not looking in ancestor factories. Useful convenience method when we expect a single bean and don't care about the bean name. Does consider objects created by FactoryBeans if the "allowEagerInit" 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 "allowEagerInit" is not set, only raw FactoryBeans will be checked (which doesn't require initialization of each FactoryBean).
| |
| beanOfTypeIncludingAncestors | back to summary |
|---|---|
| public static <T> T beanOfTypeIncludingAncestors(ListableBeanFactory lbf, Class<T> type) throws BeansException 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. Useful convenience method when we expect a single bean and don't care about the bean name. 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 Note: Beans of the same name will take precedence at the 'lowest' factory level, i.e. such beans will be returned from the lowest factory that they are being found in, hiding corresponding beans in ancestor factories. This feature allows for 'replacing' beans by explicitly choosing the same bean name in a child factory; the bean in the ancestor factory won't be visible then, not even for by-type lookups.
| |
| beanOfTypeIncludingAncestors | back to summary |
|---|---|
| public static <T> T beanOfTypeIncludingAncestors(ListableBeanFactory lbf, Class<T> type, boolean includeNonSingletons, boolean allowEagerInit) throws BeansException 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. Useful convenience method when we expect a single bean and don't care about the bean name. Does consider objects created by FactoryBeans if the "allowEagerInit" 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 "allowEagerInit" is not set, only raw FactoryBeans will be checked (which doesn't require initialization of each FactoryBean). Note: Beans of the same name will take precedence at the 'lowest' factory level, i.e. such beans will be returned from the lowest factory that they are being found in, hiding corresponding beans in ancestor factories. This feature allows for 'replacing' beans by explicitly choosing the same bean name in a child factory; the bean in the ancestor factory won't be visible then, not even for by-type lookups.
| |
| beansOfTypeIncludingAncestors | back to summary |
|---|---|
| public static <T> Map 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. The returned Map will only contain beans of this 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. Note: Beans of the same name will take precedence at the 'lowest' factory level, i.e. such beans will be returned from the lowest factory that they are being found in, hiding corresponding beans in ancestor factories. This feature allows for 'replacing' beans by explicitly choosing the same bean name in a child factory; the bean in the ancestor factory won't be visible then, not even for by-type lookups.
| |
| beansOfTypeIncludingAncestors | back to summary |
|---|---|
| public static <T> Map 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. The returned Map will only contain beans of this type. Does consider objects created by FactoryBeans if the "allowEagerInit" 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 "allowEagerInit" is not set, only raw FactoryBeans will be checked (which doesn't require initialization of each FactoryBean). Note: Beans of the same name will take precedence at the 'lowest' factory level, i.e. such beans will be returned from the lowest factory that they are being found in, hiding corresponding beans in ancestor factories. This feature allows for 'replacing' beans by explicitly choosing the same bean name in a child factory; the bean in the ancestor factory won't be visible then, not even for by-type lookups.
| |
| countBeansIncludingAncestors | back to summary |
|---|---|
| public static int countBeansIncludingAncestors(ListableBeanFactory lbf) Count all beans in any hierarchy in which this factory participates. Includes counts of ancestor bean factories. Beans that are "overridden" (specified in a descendant factory with the same name) are only counted once.
| |
| isFactoryDereference | back to summary |
|---|---|
| public static boolean isFactoryDereference(String name) Return whether the given name is a factory dereference (beginning with the factory dereference prefix).
| |
| isGeneratedBeanName | back to summary |
|---|---|
| public static boolean isGeneratedBeanName(String name) Return whether the given name is a bean name which has been generated by the default naming strategy (containing a "#..." part).
| |
| mergeNamesWithParent | back to summary |
|---|---|
| private static String[] mergeNamesWithParent(String[] result, String[] parentResult, HierarchicalBeanFactory hbf) Merge the given bean names result with the given parent result.
| |
| originalBeanName | back to summary |
|---|---|
| public static String originalBeanName(String name) Extract the "raw" bean name from the given (potentially generated) bean name, excluding any "#..." suffixes which might have been added for uniqueness.
| |
| transformedBeanName | back to summary |
|---|---|
| public static String transformedBeanName(String name) Return the actual bean name, stripping out the factory dereference prefix (if any, also stripping repeated factory prefixes if found).
| |
| uniqueBean | back to summary |
|---|---|
| private static <T> T uniqueBean(Class<T> type, Map<String, T> matchingBeans) Extract a unique bean for the given type from the given Map of matching beans.
| |