You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2019/10/31 03:08:40 UTC

[dubbo] branch master updated: init application scope configs before start referencing.

This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/master by this push:
     new c2c6cdb  init application scope configs before start referencing.
c2c6cdb is described below

commit c2c6cdb1c47df56a5222915a055fac3e4c32ca59
Author: ken.lj <ke...@gmail.com>
AuthorDate: Thu Oct 31 11:08:12 2019 +0800

    init application scope configs before start referencing.
---
 .../ReferenceAnnotationBeanPostProcessor.java      | 37 ++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/dubbo-bootstrap/dubbo-bootstrap-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessor.java b/dubbo-bootstrap/dubbo-bootstrap-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessor.java
index e347c9e..897bb8a 100644
--- a/dubbo-bootstrap/dubbo-bootstrap-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessor.java
+++ b/dubbo-bootstrap/dubbo-bootstrap-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessor.java
@@ -17,8 +17,18 @@
 package org.apache.dubbo.config.spring.beans.factory.annotation;
 
 import org.apache.dubbo.bootstrap.DubboBootstrap;
+import org.apache.dubbo.config.ApplicationConfig;
+import org.apache.dubbo.config.ConsumerConfig;
+import org.apache.dubbo.config.MetadataReportConfig;
+import org.apache.dubbo.config.MetricsConfig;
+import org.apache.dubbo.config.ModuleConfig;
+import org.apache.dubbo.config.MonitorConfig;
+import org.apache.dubbo.config.ProtocolConfig;
+import org.apache.dubbo.config.ProviderConfig;
+import org.apache.dubbo.config.RegistryConfig;
 import org.apache.dubbo.config.annotation.Reference;
 import org.apache.dubbo.config.annotation.Service;
+import org.apache.dubbo.config.spring.ConfigCenterBean;
 import org.apache.dubbo.config.spring.ReferenceBean;
 import org.apache.dubbo.config.spring.ServiceBean;
 import org.apache.dubbo.config.spring.context.event.ServiceBeanExportedEvent;
@@ -49,6 +59,7 @@ import java.util.concurrent.ConcurrentMap;
 import static java.lang.reflect.Proxy.newProxyInstance;
 import static org.apache.dubbo.config.spring.beans.factory.annotation.ServiceBeanNameBuilder.create;
 import static org.apache.dubbo.config.spring.util.AnnotationUtils.getAttribute;
+import static org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors;
 import static org.springframework.util.StringUtils.hasText;
 
 /**
@@ -84,6 +95,8 @@ public class ReferenceAnnotationBeanPostProcessor extends AnnotationInjectedBean
 
     private ApplicationContext applicationContext;
 
+    private volatile boolean preparedDubboConfigBeans;
+
     /**
      * To support the legacy annotation that is @com.alibaba.dubbo.config.annotation.Reference since 2.7.3
      */
@@ -91,6 +104,29 @@ public class ReferenceAnnotationBeanPostProcessor extends AnnotationInjectedBean
         super(Reference.class, com.alibaba.dubbo.config.annotation.Reference.class);
     }
 
+    private void prepareDubboConfigBeans() {
+
+        if (preparedDubboConfigBeans) {
+            return;
+        }
+
+        preparedDubboConfigBeans = true;
+
+        ConfigurableListableBeanFactory beanFactory = getBeanFactory();
+
+        // Initializes there Dubbo's Config Beans before @Reference bean autowiring
+        beansOfTypeIncludingAncestors(beanFactory, ApplicationConfig.class);
+        beansOfTypeIncludingAncestors(beanFactory, ModuleConfig.class);
+        beansOfTypeIncludingAncestors(beanFactory, RegistryConfig.class);
+        beansOfTypeIncludingAncestors(beanFactory, ProtocolConfig.class);
+        beansOfTypeIncludingAncestors(beanFactory, MonitorConfig.class);
+        beansOfTypeIncludingAncestors(beanFactory, ProviderConfig.class);
+        beansOfTypeIncludingAncestors(beanFactory, ConsumerConfig.class);
+        beansOfTypeIncludingAncestors(beanFactory, ConfigCenterBean.class);
+        beansOfTypeIncludingAncestors(beanFactory, MetadataReportConfig.class);
+        beansOfTypeIncludingAncestors(beanFactory, MetricsConfig.class);
+    }
+
     /**
      * Gets all beans of {@link ReferenceBean}
      *
@@ -124,6 +160,7 @@ public class ReferenceAnnotationBeanPostProcessor extends AnnotationInjectedBean
     @Override
     protected Object doGetInjectedBean(AnnotationAttributes attributes, Object bean, String beanName, Class<?> injectedType,
                                        InjectionMetadata.InjectedElement injectedElement) throws Exception {
+        prepareDubboConfigBeans();
 
         /**
          * The name of bean that annotated Dubbo's {@link Service @Service} in local Spring {@link ApplicationContext}