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).
Author
Rod Johnson
Author
Juergen Hoeller
Author
Chris Beams
Since
04.07.2003
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). |
static val GENERATED_BEAN_NAME_SEPARATOR: String
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. |
open static fun beanNamesForAnnotationIncludingAncestors(lbf: ListableBeanFactory, annotationType: Class<out Annotation>): Array<String>
Get all bean names whose |
|
open static fun beanNamesForTypeIncludingAncestors(lbf: ListableBeanFactory, type: ResolvableType): Array<String>open static fun beanNamesForTypeIncludingAncestors(lbf: ListableBeanFactory, type: Class<*>): Array<String>
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 open static fun beanNamesForTypeIncludingAncestors(lbf: ListableBeanFactory, type: Class<*>, includeNonSingletons: Boolean, allowEagerInit: Boolean): Array<String>
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). |
|
open static fun beanNamesIncludingAncestors(lbf: ListableBeanFactory): Array<String>
Return all bean names in the factory, including ancestor factories. |
|
open static fun <T : Any> beanOfType(lbf: ListableBeanFactory, type: Class<T>): T
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 open static fun <T : Any> beanOfType(lbf: ListableBeanFactory, type: Class<T>, includeNonSingletons: Boolean, allowEagerInit: Boolean): T
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). |
|
open static fun <T : Any> beanOfTypeIncludingAncestors(lbf: ListableBeanFactory, type: Class<T>): T
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. open static fun <T : Any> beanOfTypeIncludingAncestors(lbf: ListableBeanFactory, type: Class<T>, includeNonSingletons: Boolean, allowEagerInit: Boolean): T
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. |
|
open static fun <T : Any> beansOfTypeIncludingAncestors(lbf: ListableBeanFactory, type: Class<T>): MutableMap<String, T>
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. open static fun <T : Any> beansOfTypeIncludingAncestors(lbf: ListableBeanFactory, type: Class<T>, includeNonSingletons: Boolean, allowEagerInit: Boolean): MutableMap<String, T>
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. |
|
open static fun countBeansIncludingAncestors(lbf: ListableBeanFactory): Int
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. |
|
open static fun isFactoryDereference(name: String): Boolean
Return whether the given name is a factory dereference (beginning with the factory dereference prefix). |
|
open static fun isGeneratedBeanName(name: String): Boolean
Return whether the given name is a bean name which has been generated by the default naming strategy (containing a "#..." part). |
|
open static fun originalBeanName(name: String): String
Extract the "raw" bean name from the given (potentially generated) bean name, excluding any "#..." suffixes which might have been added for uniqueness. |
|
open static fun transformedBeanName(name: String): String
Return the actual bean name, stripping out the factory dereference prefix (if any, also stripping repeated factory prefixes if found). |