zoukankan      html  css  js  c++  java
  • 哈哈,原来IOC容器的bean是存在DefaultSingletonBeanRegistry的一个Map类型的属性当中。

    经过查看源代码发现IOC容器中的bean实例(不知道是不是所有的bean)是存储在一个DefaultSingletonBeanRegistry类实例的一个Map类型的属性当中

    下面是DefaultSingletonBeanRegistry类的定义:

    //类定义
    public
    class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements SingletonBeanRegistry {

    下面是这个类中的一个属性:

    /** Cache of singleton objects: bean name --> bean instance */
    //生成的bean将存储在这个属性中。初始容量为256的Map对象。
    private final Map<String, Object> singletonObjects = new ConcurrentHashMap<String, Object>(256);

    下面是DefaultSingletonBeanRegistry类的一个方法,这个方法添加bean实例到一个Map属性中

    /**
    * Add the given singleton object to the singleton cache of this factory.
    * <p>To be called for eager registration of singletons.
    * @param beanName the name of the bean //
    * @param singletonObject the singleton object
    */
    
    protected void addSingleton(String beanName, Object singletonObject) {
            synchronized (this.singletonObjects) {
           //singletonObjects 是DefaultSingletonBeanRegistry类的一个Map类型的字段。把bean实例都添加到了Map对象中。
                this.singletonObjects.put(beanName, (singletonObject != null ? singletonObject : NULL_OBJECT));
                this.singletonFactories.remove(beanName);
                this.earlySingletonObjects.remove(beanName);
                this.registeredSingletons.add(beanName);
            }
        }
  • 相关阅读:
    Echarts图表 相关技术点
    Jquery off() on() data()
    Js 正则表达式
    Java jar项目获取配置文件的项
    Java String.split 的坑,会忽略空值
    C# 工作流 状态机 门控制
    二维码SDK,高效率,高识别率,甩zxing,zbar几条街
    C#文本转语音,可导出在本地mp3或者wav文件
    api接口签名验证(MD5)
    C# 站点IP访问频率限制 针对单个站点的实现方法
  • 原文地址:https://www.cnblogs.com/GooPolaris/p/7918764.html
Copyright © 2011-2022 走看看