You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by xi...@apache.org on 2022/01/13 04:38:38 UTC

[incubator-shenyu] branch master updated: [type:fix] Exclude major classes adding @Component or @Service annotation (#2759)

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

xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new 36ff88f  [type:fix]  Exclude major classes adding @Component or @Service annotation (#2759)
36ff88f is described below

commit 36ff88ff4c2c9e410aa03f785bd7c840535823ec
Author: Sixh-PrFor <ch...@163.com>
AuthorDate: Thu Jan 13 12:09:15 2022 +0800

    [type:fix]  Exclude major classes adding @Component or @Service annotation (#2759)
    
    * Exclude ShenyuPlugin subclass and PluginDataHandler subclass without adding @Component @Service annotation
    
    * Exclude ShenyuPlugin subclass and PluginDataHandler subclass without adding @Component @Service annotation
---
 .../examples/plugin/ext/ExtPluginDataHandler.java  | 31 +++++++++++++++++-----
 .../shenyu/web/loader/ShenyuPluginLoader.java      | 12 ++++++---
 2 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/shenyu-examples/shenyu-examples-plugin/src/main/java/org/apache/shenyu/examples/plugin/ext/ExtPluginDataHandler.java b/shenyu-examples/shenyu-examples-plugin/src/main/java/org/apache/shenyu/examples/plugin/ext/ExtPluginDataHandler.java
index f2ce3f8..1d3c0cb 100644
--- a/shenyu-examples/shenyu-examples-plugin/src/main/java/org/apache/shenyu/examples/plugin/ext/ExtPluginDataHandler.java
+++ b/shenyu-examples/shenyu-examples-plugin/src/main/java/org/apache/shenyu/examples/plugin/ext/ExtPluginDataHandler.java
@@ -25,12 +25,20 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.web.reactive.DispatcherHandler;
 
+/**
+ * The type Ext plugin data handler.
+ */
 public class ExtPluginDataHandler implements PluginDataHandler {
-
+    
     private static final Logger LOG = LoggerFactory.getLogger(ExtPluginDataHandler.class);
     
     private DispatcherHandler dispatcherHandler;
     
+    /**
+     * Instantiates a new Ext plugin data handler.
+     *
+     * @param dispatcherHandler the dispatcher handler
+     */
     public ExtPluginDataHandler(final DispatcherHandler dispatcherHandler) {
         this.dispatcherHandler = dispatcherHandler;
     }
@@ -44,7 +52,7 @@ public class ExtPluginDataHandler implements PluginDataHandler {
     public void handlerPlugin(final PluginData pluginData) {
         LOG.info("hello, im extend plugin dataHandler");
     }
-
+    
     /**
      * Remove plugin.
      *
@@ -54,7 +62,7 @@ public class ExtPluginDataHandler implements PluginDataHandler {
     public void removePlugin(final PluginData pluginData) {
         LOG.info("selector removed : name = {}", pluginData.getName());
     }
-
+    
     /**
      * Handler selector.
      *
@@ -64,7 +72,7 @@ public class ExtPluginDataHandler implements PluginDataHandler {
     public void handlerSelector(final SelectorData selectorData) {
         LOG.info("selector processing : name = {}", selectorData.getName());
     }
-
+    
     /**
      * Remove selector.
      *
@@ -74,7 +82,7 @@ public class ExtPluginDataHandler implements PluginDataHandler {
     public void removeSelector(final SelectorData selectorData) {
         LOG.info("selector removed : name = {}", selectorData.getName());
     }
-
+    
     /**
      * Handler rule.
      *
@@ -84,7 +92,7 @@ public class ExtPluginDataHandler implements PluginDataHandler {
     public void handlerRule(final RuleData ruleData) {
         LOG.info("rule processing : name = {}", ruleData.getName());
     }
-
+    
     /**
      * Remove rule.
      *
@@ -94,7 +102,16 @@ public class ExtPluginDataHandler implements PluginDataHandler {
     public void removeRule(final RuleData ruleData) {
         LOG.info("rule data removed: name = {}", ruleData.getName());
     }
-
+    
+    /**
+     * Gets dispatcher handler.
+     *
+     * @return the dispatcher handler
+     */
+    public DispatcherHandler getDispatcherHandler() {
+        return dispatcherHandler;
+    }
+    
     /**
      * Plugin named string.
      *
diff --git a/shenyu-web/src/main/java/org/apache/shenyu/web/loader/ShenyuPluginLoader.java b/shenyu-web/src/main/java/org/apache/shenyu/web/loader/ShenyuPluginLoader.java
index 1141f63..f9a5556 100644
--- a/shenyu-web/src/main/java/org/apache/shenyu/web/loader/ShenyuPluginLoader.java
+++ b/shenyu-web/src/main/java/org/apache/shenyu/web/loader/ShenyuPluginLoader.java
@@ -232,9 +232,15 @@ public final class ShenyuPluginLoader extends ClassLoader implements Closeable {
             T inst = SpringBeanUtils.getInstance().getBeanByClassName(className);
             if (Objects.isNull(inst)) {
                 Class<?> clazz = Class.forName(className, false, this);
-                Annotation[] annotations = clazz.getAnnotations();
-                boolean next = Arrays.stream(annotations).anyMatch(e -> e.annotationType().equals(Component.class)
-                        || e.annotationType().equals(Service.class));
+                //Exclude  ShenyuPlugin subclass and PluginDataHandler subclass
+                // without adding @Component @Service annotation
+                boolean next = ShenyuPlugin.class.isAssignableFrom(clazz)
+                        || PluginDataHandler.class.isAssignableFrom(clazz);
+                if (!next) {
+                    Annotation[] annotations = clazz.getAnnotations();
+                    next = Arrays.stream(annotations).anyMatch(e -> e.annotationType().equals(Component.class)
+                            || e.annotationType().equals(Service.class));
+                }
                 if (next) {
                     GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
                     beanDefinition.setBeanClassName(className);