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

      

  • 相关阅读:
    索引优化策略
    mysql列类型选择
    redis安装
    redis相关面试题
    aop动态代理源码分析
    JVM运行时数据区
    redis应用场景
    JPA相关知识
    技术栈
    linux上安装mysql5.6
  • 原文地址:https://www.cnblogs.com/NathanYang/p/13813143.html
Copyright © 2020-2023  润新知