You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/06/21 02:11:43 UTC

[dubbo] branch master updated: add cache for scan result. (#7477) (#8057)

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

albumenj 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 1c6e042  add cache for scan result. (#7477) (#8057)
1c6e042 is described below

commit 1c6e0429ad55da1a37122cbf77d6c9709c262c32
Author: pazi <35...@users.noreply.github.com>
AuthorDate: Mon Jun 21 10:11:30 2021 +0800

    add cache for scan result. (#7477) (#8057)
    
    * issue: Component scan two times for @Service
    
    * add cache for scan result. (#7477)
    
    * remove redundant comments.
    
    Co-authored-by: zhang.jie <zh...@pascall.xyz>
    Co-authored-by: zhang.jie <zh...@rivamed.cn>
---
 .../DubboClassPathBeanDefinitionScanner.java       | 23 ++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/annotation/DubboClassPathBeanDefinitionScanner.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/annotation/DubboClassPathBeanDefinitionScanner.java
index 1ed2f32..13e5f37 100644
--- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/annotation/DubboClassPathBeanDefinitionScanner.java
+++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/annotation/DubboClassPathBeanDefinitionScanner.java
@@ -17,13 +17,15 @@
 package org.apache.dubbo.config.spring.context.annotation;
 
 import org.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.beans.factory.config.BeanDefinitionHolder;
 import org.springframework.beans.factory.support.BeanDefinitionRegistry;
 import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
 import org.springframework.core.env.Environment;
 import org.springframework.core.io.ResourceLoader;
 
+import java.util.Objects;
 import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 
 import static org.springframework.context.annotation.AnnotationConfigUtils.registerAnnotationConfigProcessors;
 
@@ -36,6 +38,10 @@ import static org.springframework.context.annotation.AnnotationConfigUtils.regis
  */
 public class DubboClassPathBeanDefinitionScanner extends ClassPathBeanDefinitionScanner {
 
+    /**
+     * key is package, value is BeanDefinition
+     */
+    private final ConcurrentMap<String, Set<BeanDefinition>> beanDefinitionMap = new ConcurrentHashMap<>();
 
     public DubboClassPathBeanDefinitionScanner(BeanDefinitionRegistry registry, boolean useDefaultFilters, Environment environment,
                                                ResourceLoader resourceLoader) {
@@ -58,13 +64,18 @@ public class DubboClassPathBeanDefinitionScanner extends ClassPathBeanDefinition
     }
 
     @Override
-    public Set<BeanDefinitionHolder> doScan(String... basePackages) {
-        return super.doScan(basePackages);
-    }
-
-    @Override
     public boolean checkCandidate(String beanName, BeanDefinition beanDefinition) throws IllegalStateException {
         return super.checkCandidate(beanName, beanDefinition);
     }
 
+    @Override
+    public Set<BeanDefinition> findCandidateComponents(String basePackage) {
+        Set<BeanDefinition> beanDefinitions = beanDefinitionMap.get(basePackage);
+        // if beanDefinitions size is null => scan
+        if (Objects.isNull(beanDefinitions)) {
+            beanDefinitions = super.findCandidateComponents(basePackage);
+            beanDefinitionMap.put(basePackage, beanDefinitions);
+        }
+        return beanDefinitions;
+    }
 }