ConfigurableListableBeanFactory理解

14 篇文章 0 订阅

ConfigurableListableBeanFactory接口:继承AutowireCapableBeanFactory接口,AutowireCapableBeanFactory接口又继承了beanfactory接口,因此,configurableListableBeanFactory应用上下文环境可以通过bean的name或者clazz获取指定的bean;

    /*
     * Copyright 2002-2015 the original author or authors.
     *
     * Licensed under the Apache License, Version 2.0 (the "License");
     * you may not use this file except in compliance with the License.
     * You may obtain a copy of the License at
     *
     *      http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     * limitations under the License.
     */

    package org.springframework.beans.factory.config;

    import java.util.Iterator;

    import org.springframework.beans.BeansException;
    import org.springframework.beans.factory.ListableBeanFactory;
    import org.springframework.beans.factory.NoSuchBeanDefinitionException;

    /**
     * Configuration interface to be implemented by most listable bean factories.
     * In addition to {@link ConfigurableBeanFactory}, it provides facilities(设备) to
     * analyze and modify bean definitions, and to pre-instantiate singletons.
     *
     * <p>This subinterface(子接口) of {@link org.springframework.beans.factory.BeanFactory}
     * is not meant to be used in normal application code: Stick to(依照)
     * {@link org.springframework.beans.factory.BeanFactory} or
     * {@link org.springframework.beans.factory.ListableBeanFactory} for typical
     * use cases. This interface is just meant to allow for framework-internal
     * plug'n'play even when needing access(访问) to bean factory configuration methods.
     *
     * @author Juergen Hoeller
     * @since 03.11.2003
     * @see org.springframework.context.support.AbstractApplicationContext#getBeanFactory()
     */
    public interface ConfigurableListableBeanFactory
            extends ListableBeanFactory, AutowireCapableBeanFactory, ConfigurableBeanFactory {

        /**
         * Ignore the given dependency type for autowiring:
         * for example, String. Default is none.
         * @param type the dependency type to ignore
         */
         //忽略自动注册的依赖关系。
        void ignoreDependencyType(Class<?> type);

        /**
         * Ignore the given dependency interface for autowiring.
         * <p>This will typically be used by application contexts to register
         * dependencies that are resolved in other ways, like BeanFactory through
         * BeanFactoryAware or ApplicationContext through ApplicationContextAware.
         * <p>By default, only the BeanFactoryAware interface is ignored.
         * For further types to ignore, invoke this method for each type.
         * @param ifc the dependency interface to ignore
         * @see org.springframework.beans.factory.BeanFactoryAware
         * @see org.springframework.context.ApplicationContextAware
         */
         //忽略自动注册的依赖接口
        void ignoreDependencyInterface(Class<?> ifc);

        /**
         * Register a special dependency type with corresponding(相应的) autowired value.
         * <p>This is intended for factory/context references that are supposed
         * to be autowirable but are not defined as beans in the factory:
         * e.g. a dependency of type ApplicationContext resolved to the
         * ApplicationContext instance that the bean is living in.
         * <p>Note: There are no such default types registered in a plain BeanFactory,
         * not even for the BeanFactory interface itself.
         * @param dependencyType the dependency type to register. This will typically
         * be a base interface such as BeanFactory, with extensions of it resolved
         * as well if declared as an autowiring dependency (e.g. ListableBeanFactory),
         * as long as the given value actually implements the extended interface.
         * @param autowiredValue the corresponding autowired value. This may also be an
         * implementation of the {@link org.springframework.beans.factory.ObjectFactory}
         * interface, which allows for lazy resolution of the actual target value.
         */
         //
        void registerResolvableDependency(Class<?> dependencyType, Object autowiredValue);

        /**
         * Determine whether the specified bean qualifies as an autowire candidate,
         * to be injected into other beans which declare a dependency of matching type.
         * <p>This method checks ancestor factories as well.
         * @param beanName the name of the bean to check
         * @param descriptor the descriptor of the dependency to resolve
         * @return whether the bean should be considered as autowire candidate
         * @throws NoSuchBeanDefinitionException if there is no bean with the given name
         */
        boolean isAutowireCandidate(String beanName, DependencyDescriptor descriptor)
                throws NoSuchBeanDefinitionException;

        /**
         * Return the registered BeanDefinition for the specified bean, allowing access
         * to its property values and constructor argument value (which can be
         * modified during bean factory post-processing).
         * <p>A returned BeanDefinition object should not be a copy but the original
         * definition object as registered in the factory. This means that it should
         * be castable to a more specific implementation type, if necessary.
         * <p><b>NOTE:</b> This method does <i>not</i> consider ancestor factories.
         * It is only meant for accessing local bean definitions of this factory.
         * @param beanName the name of the bean
         * @return the registered BeanDefinition
         * @throws NoSuchBeanDefinitionException if there is no bean with the given name
         * defined in this factory
         */
         //获取beanDefinition
        BeanDefinition getBeanDefinition(String beanName) throws NoSuchBeanDefinitionException;

        /**
         * Return a unified view over all bean names managed by this factory.
         * <p>Includes bean definition names as well as names of manually registered
         * singleton instances, with bean definition names consistently coming first,
         * analogous to how type/annotation specific retrieval of bean names works.
         * @return the composite iterator for the bean names view
         * @since 4.1.2
         * @see #containsBeanDefinition
         * @see #registerSingleton
         * @see #getBeanNamesForType
         * @see #getBeanNamesForAnnotation
         */
         //迭代beanNames
        Iterator<String> getBeanNamesIterator();

        /**
         * Clear the merged bean definition cache, removing entries for beans
         * which are not considered eligible for full metadata caching yet.
         * <p>Typically triggered after changes to the original bean definitions,
         * e.g. after applying a {@link BeanFactoryPostProcessor}. Note that metadata
         * for beans which have already been created at this point will be kept around.
         * @since 4.2
         * @see #getBeanDefinition
         * @see #getMergedBeanDefinition
         */
         //清除元数据缓存
        void clearMetadataCache();

        /**
         * Freeze all bean definitions, signalling that the registered bean definitions
         * will not be modified or post-processed any further.
         * <p>This allows the factory to aggressively cache bean definition metadata.
         */
        void freezeConfiguration();

        /**
         * Return whether this factory's bean definitions are frozen,
         * i.e. are not supposed to be modified or post-processed any further.
         * @return {@code true} if the factory's configuration is considered frozen
         */
         //锁定配置信息.在调用refresh时会使用到.
        boolean isConfigurationFrozen();

        /**
         * Ensure that all non-lazy-init singletons are instantiated, also considering
         * {@link org.springframework.beans.factory.FactoryBean FactoryBeans}.
         * Typically(典型的) invoked at the end of factory setup, if desired.
         * @throws BeansException if one of the singleton beans could not be created.
         * Note: This may have left the factory with some beans already initialized!
         * Call {@link #destroySingletons()} for full cleanup in this case.
         * @see #destroySingletons()
         */
         //预实例化非懒加载单例,用于解决循环依赖问题
        void preInstantiateSingletons() throws BeansException;

    }

对于该接口的使用,请查看自定义springUtils

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值