You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by zh...@apache.org on 2022/06/08 16:54:10 UTC

[incubator-shenyu] branch master updated: [ISSUE 3485] sub task1&2 @AliasFor for @ShenyuDubboClient (#3502)

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

zhangzicheng 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 ff6d0aa41 [ISSUE 3485] sub task1&2 @AliasFor for @ShenyuDubboClient (#3502)
ff6d0aa41 is described below

commit ff6d0aa413b628dd011d37e9aca1300e832f6d29
Author: sunshujie1990 <tj...@163.com>
AuthorDate: Thu Jun 9 00:54:03 2022 +0800

    [ISSUE 3485] sub task1&2 @AliasFor for @ShenyuDubboClient (#3502)
---
 .../alibaba/dubbo/AlibabaDubboServiceBeanListener.java      |  6 +++---
 .../client/apache/dubbo/ApacheDubboServiceBeanListener.java |  8 ++++----
 .../client/dubbo/common/annotation/ShenyuDubboClient.java   | 13 ++++++++++++-
 .../annotation/impl/DubboClassMultiParamServiceImpl.java    |  4 ++--
 .../service/annotation/impl/DubboClassTestServiceImpl.java  |  2 +-
 .../dubbo/service/impl/DubboClassMultiParamServiceImpl.java |  4 ++--
 .../dubbo/service/impl/DubboClassTestServiceImpl.java       |  2 +-
 .../annotation/impl/DubboClassMultiParamServiceImpl.java    |  4 ++--
 .../service/annotation/impl/DubboClassTestServiceImpl.java  |  2 +-
 .../service/xml/impl/DubboClassMultiParamServiceImpl.java   |  4 ++--
 .../dubbo/service/xml/impl/DubboClassTestServiceImpl.java   |  2 +-
 11 files changed, 31 insertions(+), 20 deletions(-)

diff --git a/shenyu-client/shenyu-client-dubbo/shenyu-client-alibaba-dubbo/src/main/java/org/apache/shenyu/client/alibaba/dubbo/AlibabaDubboServiceBeanListener.java b/shenyu-client/shenyu-client-dubbo/shenyu-client-alibaba-dubbo/src/main/java/org/apache/shenyu/client/alibaba/dubbo/AlibabaDubboServiceBeanListener.java
index 0c484e360..e7b792790 100644
--- a/shenyu-client/shenyu-client-dubbo/shenyu-client-alibaba-dubbo/src/main/java/org/apache/shenyu/client/alibaba/dubbo/AlibabaDubboServiceBeanListener.java
+++ b/shenyu-client/shenyu-client-dubbo/shenyu-client-alibaba-dubbo/src/main/java/org/apache/shenyu/client/alibaba/dubbo/AlibabaDubboServiceBeanListener.java
@@ -35,7 +35,7 @@ import org.apache.shenyu.register.common.dto.URIRegisterDTO;
 import org.springframework.aop.support.AopUtils;
 import org.springframework.context.ApplicationListener;
 import org.springframework.context.event.ContextRefreshedEvent;
-import org.springframework.core.annotation.AnnotationUtils;
+import org.springframework.core.annotation.AnnotatedElementUtils;
 import org.springframework.lang.NonNull;
 import org.springframework.util.ReflectionUtils;
 
@@ -105,7 +105,7 @@ public class AlibabaDubboServiceBeanListener implements ApplicationListener<Cont
         if (AopUtils.isAopProxy(refProxy)) {
             clazz = AopUtils.getTargetClass(refProxy);
         }
-        ShenyuDubboClient beanShenyuClient = AnnotationUtils.findAnnotation(clazz, ShenyuDubboClient.class);
+        ShenyuDubboClient beanShenyuClient = AnnotatedElementUtils.findMergedAnnotation(clazz, ShenyuDubboClient.class);
         final String superPath = buildApiSuperPath(beanShenyuClient);
         if (superPath.contains("*")) {
             Method[] methods = ReflectionUtils.getDeclaredMethods(clazz);
@@ -118,7 +118,7 @@ public class AlibabaDubboServiceBeanListener implements ApplicationListener<Cont
         }
         Method[] methods = ReflectionUtils.getUniqueDeclaredMethods(clazz);
         for (Method method : methods) {
-            ShenyuDubboClient shenyuDubboClient = method.getAnnotation(ShenyuDubboClient.class);
+            ShenyuDubboClient shenyuDubboClient = AnnotatedElementUtils.findMergedAnnotation(method, ShenyuDubboClient.class);
             if (Objects.nonNull(shenyuDubboClient)) {
                 publisher.publishEvent(buildMetaDataDTO(serviceBean, shenyuDubboClient, method, superPath));
             }
diff --git a/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/ApacheDubboServiceBeanListener.java b/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/ApacheDubboServiceBeanListener.java
index c284eb4ef..da172d1ea 100644
--- a/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/ApacheDubboServiceBeanListener.java
+++ b/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/ApacheDubboServiceBeanListener.java
@@ -36,9 +36,9 @@ import org.apache.shenyu.register.common.dto.URIRegisterDTO;
 import org.springframework.aop.support.AopUtils;
 import org.springframework.context.ApplicationListener;
 import org.springframework.context.event.ContextRefreshedEvent;
-import org.springframework.util.ReflectionUtils;
-import org.springframework.core.annotation.AnnotationUtils;
+import org.springframework.core.annotation.AnnotatedElementUtils;
 import org.springframework.lang.NonNull;
+import org.springframework.util.ReflectionUtils;
 
 import java.lang.reflect.Method;
 import java.util.Arrays;
@@ -125,7 +125,7 @@ public class ApacheDubboServiceBeanListener implements ApplicationListener<Conte
         if (AopUtils.isAopProxy(refProxy)) {
             clazz = AopUtils.getTargetClass(refProxy);
         }
-        final ShenyuDubboClient beanShenyuClient = AnnotationUtils.findAnnotation(clazz, ShenyuDubboClient.class);
+        final ShenyuDubboClient beanShenyuClient = AnnotatedElementUtils.findMergedAnnotation(clazz, ShenyuDubboClient.class);
         final String superPath = buildApiSuperPath(clazz, beanShenyuClient);
         if (superPath.contains("*")) {
             Method[] methods = ReflectionUtils.getDeclaredMethods(clazz);
@@ -138,7 +138,7 @@ public class ApacheDubboServiceBeanListener implements ApplicationListener<Conte
         }
         Method[] methods = ReflectionUtils.getUniqueDeclaredMethods(clazz);
         for (Method method : methods) {
-            ShenyuDubboClient methodShenyuClient = method.getAnnotation(ShenyuDubboClient.class);
+            ShenyuDubboClient methodShenyuClient = AnnotatedElementUtils.findMergedAnnotation(method, ShenyuDubboClient.class);
             if (Objects.nonNull(methodShenyuClient)) {
                 publisher.publishEvent(buildMetaDataDTO(serviceBean, methodShenyuClient, method, superPath));
             }
diff --git a/shenyu-client/shenyu-client-dubbo/shenyu-client-dubbo-common/src/main/java/org/apache/shenyu/client/dubbo/common/annotation/ShenyuDubboClient.java b/shenyu-client/shenyu-client-dubbo/shenyu-client-dubbo-common/src/main/java/org/apache/shenyu/client/dubbo/common/annotation/ShenyuDubboClient.java
index 4b5b21500..a021196ea 100644
--- a/shenyu-client/shenyu-client-dubbo/shenyu-client-dubbo-common/src/main/java/org/apache/shenyu/client/dubbo/common/annotation/ShenyuDubboClient.java
+++ b/shenyu-client/shenyu-client-dubbo/shenyu-client-dubbo-common/src/main/java/org/apache/shenyu/client/dubbo/common/annotation/ShenyuDubboClient.java
@@ -17,6 +17,8 @@
 
 package org.apache.shenyu.client.dubbo.common.annotation;
 
+import org.springframework.core.annotation.AliasFor;
+
 import java.lang.annotation.ElementType;
 import java.lang.annotation.Inherited;
 import java.lang.annotation.Retention;
@@ -36,7 +38,16 @@ public @interface ShenyuDubboClient {
      *
      * @return the string
      */
-    String path();
+    @AliasFor(attribute = "path")
+    String value() default "";
+
+    /**
+     * Path string.
+     *
+     * @return the string
+     */
+    @AliasFor(attribute = "value")
+    String path() default "";
 
     /**
      * Rule name string.
diff --git a/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/service/annotation/impl/DubboClassMultiParamServiceImpl.java b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/service/annotation/impl/DubboClassMultiParamServiceImpl.java
index 3098836d2..00c3509ca 100644
--- a/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/service/annotation/impl/DubboClassMultiParamServiceImpl.java
+++ b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/service/annotation/impl/DubboClassMultiParamServiceImpl.java
@@ -32,12 +32,12 @@ import java.util.stream.Collectors;
 /**
  * The type Dubbo multi param service.
  */
-@ShenyuDubboClient(path = "/demo")
+@ShenyuDubboClient("/demo")
 @Service
 public class DubboClassMultiParamServiceImpl implements DubboClassMultiParamService {
 
     @Override
-    @ShenyuDubboClient(path = "/findByIdsAndName", desc = "findByIdsAndName")
+    @ShenyuDubboClient("/findByIdsAndName")
     public DubboTest findByIdsAndName(final List<Integer> ids, final String name) {
         return new DubboTest(ids.toString(), "hello world shenyu alibaba dubbo param findByIdsAndName :" + name);
     }
diff --git a/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/service/annotation/impl/DubboClassTestServiceImpl.java b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/service/annotation/impl/DubboClassTestServiceImpl.java
index 2f28d211c..41660dfc4 100644
--- a/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/service/annotation/impl/DubboClassTestServiceImpl.java
+++ b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/service/annotation/impl/DubboClassTestServiceImpl.java
@@ -33,7 +33,7 @@ import java.util.Random;
 /**
  * The type Dubbo service.
  */
-@ShenyuDubboClient(path = "/demo/**", desc = "class init")
+@ShenyuDubboClient("/demo/**")
 @Service
 public class DubboClassTestServiceImpl implements DubboClassTestService {
 
diff --git a/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/service/impl/DubboClassMultiParamServiceImpl.java b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/service/impl/DubboClassMultiParamServiceImpl.java
index 27996573f..9f9d8f30c 100644
--- a/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/service/impl/DubboClassMultiParamServiceImpl.java
+++ b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/service/impl/DubboClassMultiParamServiceImpl.java
@@ -33,11 +33,11 @@ import java.util.stream.Collectors;
  * The type Dubbo multi param service.
  */
 @Service("dubboClassMultiParamService")
-@ShenyuDubboClient(path = "/demo")
+@ShenyuDubboClient("/demo")
 public class DubboClassMultiParamServiceImpl implements DubboClassMultiParamService {
     
     @Override
-    @ShenyuDubboClient(path = "/findByIdsAndName", desc = "findByIdsAndName")
+    @ShenyuDubboClient("/findByIdsAndName")
     public DubboTest findByIdsAndName(final List<Integer> ids, final String name) {
         return new DubboTest(ids.toString(), "hello world shenyu alibaba dubbo param findByIdsAndName :" + name);
     }
diff --git a/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/service/impl/DubboClassTestServiceImpl.java b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/service/impl/DubboClassTestServiceImpl.java
index d5f046af2..4e9f9c1d9 100644
--- a/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/service/impl/DubboClassTestServiceImpl.java
+++ b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-alibaba-dubbo-service/src/main/java/org/apache/shenyu/examples/alibaba/dubbo/service/impl/DubboClassTestServiceImpl.java
@@ -29,7 +29,7 @@ import java.util.Random;
  * DubboTestServiceImpl.
  */
 @Service("dubboClassTestService")
-@ShenyuDubboClient(path = "/demo/**", desc = "class init")
+@ShenyuDubboClient("/demo/**")
 public class DubboClassTestServiceImpl implements DubboClassTestService {
     
     @Override
diff --git a/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-apache-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/apache/dubbo/service/annotation/impl/DubboClassMultiParamServiceImpl.java b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-apache-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/apache/dubbo/service/annotation/impl/DubboClassMultiParamServiceImpl.java
index 45b035290..dca4ff532 100644
--- a/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-apache-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/apache/dubbo/service/annotation/impl/DubboClassMultiParamServiceImpl.java
+++ b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-apache-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/apache/dubbo/service/annotation/impl/DubboClassMultiParamServiceImpl.java
@@ -32,12 +32,12 @@ import java.util.stream.Collectors;
 /**
  * The type Dubbo multi param service.
  */
-@ShenyuDubboClient(path = "/demo")
+@ShenyuDubboClient("/demo")
 @DubboService
 public class DubboClassMultiParamServiceImpl implements DubboClassMultiParamService {
     
     @Override
-    @ShenyuDubboClient(path = "/findByIdsAndName", desc = "findByIdsAndName")
+    @ShenyuDubboClient("/findByIdsAndName")
     public DubboTest findByIdsAndName(final List<Integer> ids, final String name) {
         return new DubboTest(ids.toString(), "hello world shenyu apache dubbo param findByIdsAndName :" + name);
     }
diff --git a/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-apache-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/apache/dubbo/service/annotation/impl/DubboClassTestServiceImpl.java b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-apache-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/apache/dubbo/service/annotation/impl/DubboClassTestServiceImpl.java
index 2a6078783..64d73dc6b 100644
--- a/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-apache-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/apache/dubbo/service/annotation/impl/DubboClassTestServiceImpl.java
+++ b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-apache-dubbo-service-annotation/src/main/java/org/apache/shenyu/examples/apache/dubbo/service/annotation/impl/DubboClassTestServiceImpl.java
@@ -32,7 +32,7 @@ import java.util.Random;
 /**
  * The type Dubbo service.
  */
-@ShenyuDubboClient(path = "/demo/**", desc = "class init")
+@ShenyuDubboClient("/demo/**")
 @DubboService
 public class DubboClassTestServiceImpl implements DubboClassTestService {
 
diff --git a/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-apache-dubbo-service-xml/src/main/java/org/apache/shenyu/examples/apache/dubbo/service/xml/impl/DubboClassMultiParamServiceImpl.java b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-apache-dubbo-service-xml/src/main/java/org/apache/shenyu/examples/apache/dubbo/service/xml/impl/DubboClassMultiParamServiceImpl.java
index 6d6782849..53213c7a7 100644
--- a/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-apache-dubbo-service-xml/src/main/java/org/apache/shenyu/examples/apache/dubbo/service/xml/impl/DubboClassMultiParamServiceImpl.java
+++ b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-apache-dubbo-service-xml/src/main/java/org/apache/shenyu/examples/apache/dubbo/service/xml/impl/DubboClassMultiParamServiceImpl.java
@@ -33,11 +33,11 @@ import java.util.stream.Collectors;
  * The type Dubbo multi param service.
  */
 @Service("dubboClassMultiParamService")
-@ShenyuDubboClient(path = "/demo")
+@ShenyuDubboClient("/demo")
 public class DubboClassMultiParamServiceImpl implements DubboClassMultiParamService {
     
     @Override
-    @ShenyuDubboClient(path = "/findByIdsAndName", desc = "findByIdsAndName")
+    @ShenyuDubboClient("/findByIdsAndName")
     public DubboTest findByIdsAndName(final List<Integer> ids, final String name) {
         return new DubboTest(ids.toString(), "hello world shenyu apache dubbo param findByIdsAndName :" + name);
     }
diff --git a/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-apache-dubbo-service-xml/src/main/java/org/apache/shenyu/examples/apache/dubbo/service/xml/impl/DubboClassTestServiceImpl.java b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-apache-dubbo-service-xml/src/main/java/org/apache/shenyu/examples/apache/dubbo/service/xml/impl/DubboClassTestServiceImpl.java
index d89bd1ec0..1cd8ae39a 100644
--- a/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-apache-dubbo-service-xml/src/main/java/org/apache/shenyu/examples/apache/dubbo/service/xml/impl/DubboClassTestServiceImpl.java
+++ b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-apache-dubbo-service-xml/src/main/java/org/apache/shenyu/examples/apache/dubbo/service/xml/impl/DubboClassTestServiceImpl.java
@@ -29,7 +29,7 @@ import java.util.Random;
  * DubboTestServiceImpl.
  */
 @Service("dubboClassTestService")
-@ShenyuDubboClient(path = "/demo/**", desc = "class init")
+@ShenyuDubboClient("/demo/**")
 public class DubboClassTestServiceImpl implements DubboClassTestService {
     
     @Override