接口 ListableBeanFactory

    • 方法详细资料

      • 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, and ignores any singleton beans that have been registered by other means than bean definitions.

        参数:
        beanName - the name of the bean to look for
        返回:
        if this bean factory contains a bean definition with the given name
        另请参阅:
        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, and ignores any singleton beans that have been registered by other means than bean definitions.

        返回:
        the number of beans defined in the factory
      • getBeanDefinitionNames

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

        Does not consider any hierarchy this factory may participate in, and ignores any singleton beans that have been registered by other means than bean definitions.

        返回:
        the names of all beans defined in this factory, or an empty array if none defined
      • getBeanNamesForType

        String[] getBeanNamesForType​(ResolvableType 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.

        NOTE: This method introspects top-level beans only. It does not check nested beans which might match the specified type as well.

        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 getBeanNamesForType(type, true, true).

        Bean names returned by this method should always return bean names in the order of definition in the backend configuration, as far as possible.

        参数:
        type - the class or interface to match, or null for all bean names
        返回:
        the names of beans (or objects created by FactoryBeans) matching the given object type (including subclasses), or an empty array if none
        从以下版本开始:
        4.2
        另请参阅:
        BeanFactory.isTypeMatch(String, ResolvableType), FactoryBean.getObjectType(), BeanFactoryUtils.beanNamesForTypeIncludingAncestors(ListableBeanFactory, ResolvableType)
      • 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.

        NOTE: This method introspects top-level beans only. It does not check nested beans which might match the specified type as well.

        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 getBeanNamesForType(type, true, true).

        Bean names returned by this method should always return bean names in the order of definition in the backend configuration, as far as possible.

        参数:
        type - the class or interface to match, or null for all bean names
        返回:
        the names of beans (or objects created by FactoryBeans) matching the given object type (including subclasses), or an empty array if none
        另请参阅:
        FactoryBean.getObjectType(), BeanFactoryUtils.beanNamesForTypeIncludingAncestors(ListableBeanFactory, Class)
      • getBeanNamesForType

        String[] getBeanNamesForType​(Class<?> type,
                                     boolean includeNonSingletons,
                                     boolean allowEagerInit)
        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.

        NOTE: This method introspects top-level beans only. It does not check nested beans which might match the specified type as well.

        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).

        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.

        Bean names returned by this method should always return bean names in the order of definition in the backend configuration, as far as possible.

        参数:
        type - the class or interface to match, or null for all bean names
        includeNonSingletons - whether to include prototype or scoped beans too or just singletons (also applies to FactoryBeans)
        allowEagerInit - 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.
        返回:
        the names of beans (or objects created by FactoryBeans) matching the given object type (including subclasses), or an empty array if none
        另请参阅:
        FactoryBean.getObjectType(), BeanFactoryUtils.beanNamesForTypeIncludingAncestors(ListableBeanFactory, Class, boolean, boolean)
      • getBeansOfType

        <T> Map<String,​T> getBeansOfType​(Class<T> 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.

        NOTE: This method introspects top-level beans only. It does not check nested beans which might match the specified type as well.

        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).

        The Map returned by this method should always return bean names and corresponding bean instances in the order of definition in the backend configuration, as far as possible.

        参数:
        type - the class or interface to match, or null for all concrete beans
        返回:
        a Map with the matching beans, containing the bean names as keys and the corresponding bean instances as values
        抛出:
        BeansException - if a bean could not be created
        从以下版本开始:
        1.1.2
        另请参阅:
        FactoryBean.getObjectType(), BeanFactoryUtils.beansOfTypeIncludingAncestors(ListableBeanFactory, Class)
      • getBeansOfType

        <T> Map<String,​T> getBeansOfType​(Class<T> type,
                                               boolean includeNonSingletons,
                                               boolean allowEagerInit)
                                        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.

        NOTE: This method introspects top-level beans only. It does not check nested beans which might match the specified type as well.

        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).

        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.

        The Map returned by this method should always return bean names and corresponding bean instances in the order of definition in the backend configuration, as far as possible.

        参数:
        type - the class or interface to match, or null for all concrete beans
        includeNonSingletons - whether to include prototype or scoped beans too or just singletons (also applies to FactoryBeans)
        allowEagerInit - 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.
        返回:
        a Map with the matching beans, containing the bean names as keys and the corresponding bean instances as values
        抛出:
        BeansException - if a bean could not be created
        另请参阅:
        FactoryBean.getObjectType(), BeanFactoryUtils.beansOfTypeIncludingAncestors(ListableBeanFactory, Class, boolean, boolean)
      • getBeanNamesForAnnotation

        String[] getBeanNamesForAnnotation​(Class<? extends Annotation> annotationType)
        Find all names of beans which are annotated with the supplied Annotation type, without creating corresponding bean instances yet.

        Note that this method considers objects created by FactoryBeans, which means that FactoryBeans will get initialized in order to determine their object type.

        参数:
        annotationType - the type of annotation to look for
        返回:
        the names of all matching beans
        从以下版本开始:
        4.0
        另请参阅:
        findAnnotationOnBean(java.lang.String, java.lang.Class<A>)
      • getBeansWithAnnotation

        Map<String,​ObjectgetBeansWithAnnotation​(Class<? extends Annotation> annotationType)
                                                 throws BeansException
        Find all beans which are annotated with the supplied Annotation type, returning a Map of bean names with corresponding bean instances.

        Note that this method considers objects created by FactoryBeans, which means that FactoryBeans will get initialized in order to determine their object type.

        参数:
        annotationType - the type of annotation to look for
        返回:
        a Map with the matching beans, containing the bean names as keys and the corresponding bean instances as values
        抛出:
        BeansException - if a bean could not be created
        从以下版本开始:
        3.0
        另请参阅:
        findAnnotationOnBean(java.lang.String, java.lang.Class<A>)