zoukankan      html  css  js  c++  java
  • RefreshScope

    What is RefreshScope ? 

       RefreshScope(org.springframework.cloud.context.scope.refresh)是spring cloud提供的一种特殊的scope实现,用来实现配置、实例热加载。 RefreshScope继承关系如下所示
     

     

     

     Scope -> GenericScope -> RefreshScope,Scope是Spring2.0开始有的概念,主要是用于定义spring的注入范围。GenericScope 是 一个通用Scope实现。

    2. RefreshScope实现原理

    要想了解RefreshScope的实现原理,首先要了解Scope在Springboot生命周期中涉及到的功能点

     2.1 Scope在创建Bean实例

    AbstractBeanFactory#doGetBean
    此方法返回一个Bean对象
      /*
         * Return an instance, which may be shared or independent, of the specified bean.
         */
        protected <T> T doGetBean(...) {
            final String beanName = transformedBeanName(name);
            Object bean;
            // Eagerly check singleton cache for manually registered singletons.
            Object sharedInstance = getSingleton(beanName);
            if (sharedInstance != null && args == null) {
                ...
                bean = getObjectForBeanInstance(sharedInstance, name, beanName, null);
            }
    
        }else {
            // Fail if we're already creating this bean instance:
            // We're assumably within a circular reference.
            ...
            // Check if bean definition exists in this factory.
            ...
            // Guarantee initialization of beans that the current bean depends on.
            ....
            //Create bean instance.
            if (mbd.isSingleton()) {
            ...
            } else if (mbd.isPrototype())
                ...
    
            {
                String scopeName = mbd.getScope();
                final Scope scope = this.scopes.get(scopeName);
                Object scopedInstance = scope.get(beanName, new ObjectFactory<Object>() {...
                });
            ...
            }
            ...
        }
    

      

  • 相关阅读:
    GDI 设备环境句柄(2)
    GDI 像素(5)
    Api+Mvc增删查改
    sql语句全
    Mvc 导出
    触发器、事务
    计算时间戳的差
    SQL行转列经典例子(转载)
    Socket (套接字)通信
    MVC上传图片
  • 原文地址:https://www.cnblogs.com/NathanYang/p/13813143.html
Copyright © 2011-2022 走看看