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>() {...
                });
            ...
            }
            ...
        }
    

      

  • 相关阅读:
    Android Hal 分析
    Android JNI 使用的数据结构JNINativeMethod详解
    MTK GPIO 一些理解
    DEVICE_ATTR
    DEVICE_ATTR
    内核驱动中常见的miscdevice、platform_device、platform_driver
    DEVICE_ATTR实例分析
    虚拟机安装Ubuntu14.04打开FireFox提示Server not found
    Android编译系统中的Kconfig,Makefile,.config编译系统浅析
    几款在线脑图制作工具
  • 原文地址:https://www.cnblogs.com/NathanYang/p/13813143.html
Copyright © 2011-2022 走看看