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/13 10:41:50 UTC

[incubator-shenyu] branch master updated: fix issue #3485 (#3542)

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 a9731d15d fix issue #3485 (#3542)
a9731d15d is described below

commit a9731d15d8afe930fde10f6e604f2c4d003f88a5
Author: ShawnSiao <xi...@qq.com>
AuthorDate: Mon Jun 13 18:41:42 2022 +0800

    fix issue #3485 (#3542)
---
 .../client/sofa/SofaServiceBeanPostProcessor.java    |  8 ++++----
 .../sofa/common/annotation/ShenyuSofaClient.java     | 14 +++++++++++++-
 .../impl/SofaClientMultiParamServiceImpl.java        | 20 ++++++++++----------
 .../impl/SofaClientSingleParamServiceImpl.java       |  8 ++++----
 .../sofa/service/impl/SofaMultiParamServiceImpl.java | 18 +++++++++---------
 .../service/impl/SofaSingleParamServiceImpl.java     |  6 +++---
 6 files changed, 43 insertions(+), 31 deletions(-)

diff --git a/shenyu-client/shenyu-client-sofa/src/main/java/org/apache/shenyu/client/sofa/SofaServiceBeanPostProcessor.java b/shenyu-client/shenyu-client-sofa/src/main/java/org/apache/shenyu/client/sofa/SofaServiceBeanPostProcessor.java
index 5ea11eb71..605b4cc94 100644
--- a/shenyu-client/shenyu-client-sofa/src/main/java/org/apache/shenyu/client/sofa/SofaServiceBeanPostProcessor.java
+++ b/shenyu-client/shenyu-client-sofa/src/main/java/org/apache/shenyu/client/sofa/SofaServiceBeanPostProcessor.java
@@ -46,7 +46,7 @@ import org.slf4j.LoggerFactory;
 import org.springframework.aop.support.AopUtils;
 import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.config.BeanPostProcessor;
-import org.springframework.core.annotation.AnnotationUtils;
+import org.springframework.core.annotation.AnnotatedElementUtils;
 import org.springframework.lang.NonNull;
 import org.springframework.util.ReflectionUtils;
 
@@ -90,7 +90,7 @@ public class SofaServiceBeanPostProcessor implements BeanPostProcessor {
     }
 
     @Override
-    public Object postProcessAfterInitialization(final Object bean, final String beanName) throws BeansException {
+    public Object postProcessAfterInitialization(@NonNull final Object bean, final String beanName) throws BeansException {
         if (bean instanceof ServiceFactoryBean) {
             executorService.execute(() -> handler((ServiceFactoryBean) bean));
         }
@@ -110,7 +110,7 @@ public class SofaServiceBeanPostProcessor implements BeanPostProcessor {
         if (AopUtils.isAopProxy(targetProxy)) {
             clazz = AopUtils.getTargetClass(targetProxy);
         }
-        final ShenyuSofaClient beanSofaClient = AnnotationUtils.findAnnotation(clazz, ShenyuSofaClient.class);
+        final ShenyuSofaClient beanSofaClient = AnnotatedElementUtils.findMergedAnnotation(clazz, ShenyuSofaClient.class);
         final String superPath = buildApiSuperPath(beanSofaClient);
         if (superPath.contains("*")) {
             Method[] declaredMethods = ReflectionUtils.getDeclaredMethods(clazz);
@@ -123,7 +123,7 @@ public class SofaServiceBeanPostProcessor implements BeanPostProcessor {
         }
         Method[] methods = ReflectionUtils.getUniqueDeclaredMethods(clazz);
         for (Method method : methods) {
-            ShenyuSofaClient methodSofaClient = method.getAnnotation(ShenyuSofaClient.class);
+            ShenyuSofaClient methodSofaClient = AnnotatedElementUtils.findMergedAnnotation(method, ShenyuSofaClient.class);
             if (Objects.nonNull(methodSofaClient)) {
                 publisher.publishEvent(buildMetaDataDTO(serviceBean, methodSofaClient, method, superPath));
             }
diff --git a/shenyu-client/shenyu-client-sofa/src/main/java/org/apache/shenyu/client/sofa/common/annotation/ShenyuSofaClient.java b/shenyu-client/shenyu-client-sofa/src/main/java/org/apache/shenyu/client/sofa/common/annotation/ShenyuSofaClient.java
index 2b9be516a..5e1354e80 100644
--- a/shenyu-client/shenyu-client-sofa/src/main/java/org/apache/shenyu/client/sofa/common/annotation/ShenyuSofaClient.java
+++ b/shenyu-client/shenyu-client-sofa/src/main/java/org/apache/shenyu/client/sofa/common/annotation/ShenyuSofaClient.java
@@ -17,6 +17,8 @@
 
 package org.apache.shenyu.client.sofa.common.annotation;
 
+import org.springframework.core.annotation.AliasFor;
+
 import java.lang.annotation.ElementType;
 import java.lang.annotation.Inherited;
 import java.lang.annotation.Retention;
@@ -30,12 +32,22 @@ import java.lang.annotation.Target;
 @Target({ElementType.TYPE, ElementType.METHOD})
 @Inherited
 public @interface ShenyuSofaClient {
+    
+    /**
+     * Path string.
+     *
+     * @return the string
+     */
+    @AliasFor(attribute = "path")
+    String value() default "";
+    
     /**
      * Path string.
      *
      * @return the string
      */
-    String path();
+    @AliasFor(attribute = "value")
+    String path() default "";
 
     /**
      * Rule name string.
diff --git a/shenyu-examples/shenyu-examples-sofa/shenyu-examples-sofa-service/src/main/java/org/apache/shenyu/examples/sofa/service/impl/SofaClientMultiParamServiceImpl.java b/shenyu-examples/shenyu-examples-sofa/shenyu-examples-sofa-service/src/main/java/org/apache/shenyu/examples/sofa/service/impl/SofaClientMultiParamServiceImpl.java
index 19f157321..fc9552ff9 100644
--- a/shenyu-examples/shenyu-examples-sofa/shenyu-examples-sofa-service/src/main/java/org/apache/shenyu/examples/sofa/service/impl/SofaClientMultiParamServiceImpl.java
+++ b/shenyu-examples/shenyu-examples-sofa/shenyu-examples-sofa-service/src/main/java/org/apache/shenyu/examples/sofa/service/impl/SofaClientMultiParamServiceImpl.java
@@ -33,36 +33,36 @@ import java.util.stream.Collectors;
 /**
  * Sofa multi parameter service.
  */
-@ShenyuSofaClient(path="/demo")
+@ShenyuSofaClient("/demo")
 @Service
 public class SofaClientMultiParamServiceImpl implements SofaClientMultiParamService {
     
     @Override
-    @ShenyuSofaClient(path = "/findByIdsAndName", desc = "findByIdsAndName")
+    @ShenyuSofaClient("/findByIdsAndName")
     public SofaSimpleTypeBean findByIdsAndName(final List<Integer> ids, final String name) {
         return new SofaSimpleTypeBean(ids.toString(), "hello world shenyu sofa param findByIdsAndName :" + name);
     }
     
     @Override
-    @ShenyuSofaClient(path = "/findByArrayIdsAndName", desc = "findByIdsAndName")
+    @ShenyuSofaClient("/findByArrayIdsAndName")
     public SofaSimpleTypeBean findByArrayIdsAndName(final Integer[] ids, final String name) {
         return new SofaSimpleTypeBean(Arrays.toString(ids), "hello world shenyu sofa param findByArrayIdsAndName :" + name);
     }
     
     @Override
-    @ShenyuSofaClient(path = "/findByStringArray", desc = "findByStringArray")
+    @ShenyuSofaClient("/findByStringArray")
     public SofaSimpleTypeBean findByStringArray(final String[] ids) {
         return new SofaSimpleTypeBean(Arrays.toString(ids), "hello world shenyu sofa param findByStringArray");
     }
     
     @Override
-    @ShenyuSofaClient(path = "/findByListId", desc = "findByListId")
+    @ShenyuSofaClient("/findByListId")
     public SofaSimpleTypeBean findByListId(final List<String> ids) {
         return new SofaSimpleTypeBean(ids.toString(), "hello world shenyu sofa param findByListId");
     }
     
     @Override
-    @ShenyuSofaClient(path = "/batchSave", desc = "batchSave")
+    @ShenyuSofaClient("/batchSave")
     public SofaSimpleTypeBean batchSave(final List<SofaSimpleTypeBean> sofaTestList) {
         final String id = sofaTestList.stream().map(SofaSimpleTypeBean::getId).collect(Collectors.joining("-"));
         final String name = "hello world shenyu sofa param batchSave :"
@@ -73,7 +73,7 @@ public class SofaClientMultiParamServiceImpl implements SofaClientMultiParamServ
     }
     
     @Override
-    @ShenyuSofaClient(path = "/batchSaveNameAndId", desc = "batchSaveNameAndId")
+    @ShenyuSofaClient("/batchSaveNameAndId")
     public SofaSimpleTypeBean batchSaveNameAndId(final List<SofaSimpleTypeBean> sofaTestList, final String id, final String name) {
         final String newName = "hello world shenyu sofa param batchSaveAndNameAndId :" + name + ":"
                 + sofaTestList.stream()
@@ -83,7 +83,7 @@ public class SofaClientMultiParamServiceImpl implements SofaClientMultiParamServ
     }
     
     @Override
-    @ShenyuSofaClient(path = "/saveComplexBean", desc = "saveComplexBean")
+    @ShenyuSofaClient("/saveComplexBean")
     public SofaSimpleTypeBean saveComplexBean(final SofaComplexTypeBean sofaComplexTypeBean) {
         final String id = sofaComplexTypeBean.getIdLists().toString();
         final String typeName = "hello world shenyu sofa param saveComplexBean :" + sofaComplexTypeBean.getSofaSimpleTypeBean().getName();
@@ -91,7 +91,7 @@ public class SofaClientMultiParamServiceImpl implements SofaClientMultiParamServ
     }
     
     @Override
-    @ShenyuSofaClient(path = "/saveComplexBeanAndName", desc = "saveComplexBeanAndName")
+    @ShenyuSofaClient("/saveComplexBeanAndName")
     public SofaSimpleTypeBean saveComplexBeanAndName(final SofaComplexTypeBean sofaComplexTypeBean, final String name) {
         final String id = sofaComplexTypeBean.getIdLists().toString();
         final String typeName = "hello world shenyu sofa param saveComplexBeanAndName :" + sofaComplexTypeBean.getSofaSimpleTypeBean().getName() + "-" + name;
@@ -99,7 +99,7 @@ public class SofaClientMultiParamServiceImpl implements SofaClientMultiParamServ
     }
     
     @Override
-    @ShenyuSofaClient(path = "/saveTwoList", desc = "saveTwoList")
+    @ShenyuSofaClient("/saveTwoList")
     public SofaSimpleTypeBean saveTwoList(final List<SofaComplexTypeBean> sofaComplexTypeBeanList, final Map<String, SofaSimpleTypeBean> sofaSimpleTypeBeanMap) {
         SofaSimpleTypeBean simpleTypeBean = new SofaSimpleTypeBean();
         if (!CollectionUtils.isEmpty(sofaComplexTypeBeanList) && !CollectionUtils.isEmpty(sofaSimpleTypeBeanMap)) {
diff --git a/shenyu-examples/shenyu-examples-sofa/shenyu-examples-sofa-service/src/main/java/org/apache/shenyu/examples/sofa/service/impl/SofaClientSingleParamServiceImpl.java b/shenyu-examples/shenyu-examples-sofa/shenyu-examples-sofa-service/src/main/java/org/apache/shenyu/examples/sofa/service/impl/SofaClientSingleParamServiceImpl.java
index 5cb8866a1..859bbc01c 100644
--- a/shenyu-examples/shenyu-examples-sofa/shenyu-examples-sofa-service/src/main/java/org/apache/shenyu/examples/sofa/service/impl/SofaClientSingleParamServiceImpl.java
+++ b/shenyu-examples/shenyu-examples-sofa/shenyu-examples-sofa-service/src/main/java/org/apache/shenyu/examples/sofa/service/impl/SofaClientSingleParamServiceImpl.java
@@ -27,24 +27,24 @@ import java.util.Random;
 /**
  * Sofa single param service.
  */
-@ShenyuSofaClient(path="/demo/**")
+@ShenyuSofaClient("/demo/**")
 @Service
 public class SofaClientSingleParamServiceImpl implements SofaClientSingleParamService {
     
     @Override
-    @ShenyuSofaClient(path = "/findById", desc = "Find by Id")
+    @ShenyuSofaClient("/findById")
     public SofaSimpleTypeBean findById(final String id) {
         return new SofaSimpleTypeBean(id, "hello world shenyu Sofa, findById");
     }
     
     @Override
-    @ShenyuSofaClient(path = "/findAll", desc = "Get all data")
+    @ShenyuSofaClient("/findAll")
     public SofaSimpleTypeBean findAll() {
         return new SofaSimpleTypeBean(String.valueOf(new Random().nextInt()), "hello world shenyu Sofa , findAll");
     }
     
     @Override
-    @ShenyuSofaClient(path = "/insert", desc = "Insert a row of data")
+    @ShenyuSofaClient("/insert")
     public SofaSimpleTypeBean insert(final SofaSimpleTypeBean sofaSimpleTypeBean) {
         sofaSimpleTypeBean.setName("hello world shenyu Sofa: " + sofaSimpleTypeBean.getName());
         return sofaSimpleTypeBean;
diff --git a/shenyu-examples/shenyu-examples-sofa/shenyu-examples-sofa-service/src/main/java/org/apache/shenyu/examples/sofa/service/impl/SofaMultiParamServiceImpl.java b/shenyu-examples/shenyu-examples-sofa/shenyu-examples-sofa-service/src/main/java/org/apache/shenyu/examples/sofa/service/impl/SofaMultiParamServiceImpl.java
index 08aef374e..d099c6e8a 100644
--- a/shenyu-examples/shenyu-examples-sofa/shenyu-examples-sofa-service/src/main/java/org/apache/shenyu/examples/sofa/service/impl/SofaMultiParamServiceImpl.java
+++ b/shenyu-examples/shenyu-examples-sofa/shenyu-examples-sofa-service/src/main/java/org/apache/shenyu/examples/sofa/service/impl/SofaMultiParamServiceImpl.java
@@ -37,31 +37,31 @@ import java.util.stream.Collectors;
 public class SofaMultiParamServiceImpl implements SofaMultiParamService {
 
     @Override
-    @ShenyuSofaClient(path = "/findByIdsAndName", desc = "findByIdsAndName")
+    @ShenyuSofaClient("/findByIdsAndName")
     public SofaSimpleTypeBean findByIdsAndName(final List<Integer> ids, final String name) {
         return new SofaSimpleTypeBean(ids.toString(), "hello world shenyu sofa param findByIdsAndName :" + name);
     }
 
     @Override
-    @ShenyuSofaClient(path = "/findByArrayIdsAndName", desc = "findByIdsAndName")
+    @ShenyuSofaClient("/findByArrayIdsAndName")
     public SofaSimpleTypeBean findByArrayIdsAndName(final Integer[] ids, final String name) {
         return new SofaSimpleTypeBean(Arrays.toString(ids), "hello world shenyu sofa param findByArrayIdsAndName :" + name);
     }
 
     @Override
-    @ShenyuSofaClient(path = "/findByStringArray", desc = "findByStringArray")
+    @ShenyuSofaClient("/findByStringArray")
     public SofaSimpleTypeBean findByStringArray(final String[] ids) {
         return new SofaSimpleTypeBean(Arrays.toString(ids), "hello world shenyu sofa param findByStringArray");
     }
 
     @Override
-    @ShenyuSofaClient(path = "/findByListId", desc = "findByListId")
+    @ShenyuSofaClient("/findByListId")
     public SofaSimpleTypeBean findByListId(final List<String> ids) {
         return new SofaSimpleTypeBean(ids.toString(), "hello world shenyu sofa param findByListId");
     }
 
     @Override
-    @ShenyuSofaClient(path = "/batchSave", desc = "batchSave")
+    @ShenyuSofaClient("/batchSave")
     public SofaSimpleTypeBean batchSave(final List<SofaSimpleTypeBean> sofaTestList) {
         final String id = sofaTestList.stream().map(SofaSimpleTypeBean::getId).collect(Collectors.joining("-"));
         final String name = "hello world shenyu sofa param batchSave :"
@@ -72,7 +72,7 @@ public class SofaMultiParamServiceImpl implements SofaMultiParamService {
     }
 
     @Override
-    @ShenyuSofaClient(path = "/batchSaveNameAndId", desc = "batchSaveNameAndId")
+    @ShenyuSofaClient("/batchSaveNameAndId")
     public SofaSimpleTypeBean batchSaveNameAndId(final List<SofaSimpleTypeBean> sofaTestList, final String id, final String name) {
         final String newName = "hello world shenyu sofa param batchSaveAndNameAndId :" + name + ":"
                 + sofaTestList.stream()
@@ -82,7 +82,7 @@ public class SofaMultiParamServiceImpl implements SofaMultiParamService {
     }
 
     @Override
-    @ShenyuSofaClient(path = "/saveComplexBean", desc = "saveComplexBean")
+    @ShenyuSofaClient("/saveComplexBean")
     public SofaSimpleTypeBean saveComplexBean(final SofaComplexTypeBean sofaComplexTypeBean) {
         final String id = sofaComplexTypeBean.getIdLists().toString();
         final String typeName = "hello world shenyu sofa param saveComplexBean :" + sofaComplexTypeBean.getSofaSimpleTypeBean().getName();
@@ -90,7 +90,7 @@ public class SofaMultiParamServiceImpl implements SofaMultiParamService {
     }
 
     @Override
-    @ShenyuSofaClient(path = "/saveComplexBeanAndName", desc = "saveComplexBeanAndName")
+    @ShenyuSofaClient("/saveComplexBeanAndName")
     public SofaSimpleTypeBean saveComplexBeanAndName(final SofaComplexTypeBean sofaComplexTypeBean, final String name) {
         final String id = sofaComplexTypeBean.getIdLists().toString();
         final String typeName = "hello world shenyu sofa param saveComplexBeanAndName :" + sofaComplexTypeBean.getSofaSimpleTypeBean().getName() + "-" + name;
@@ -98,7 +98,7 @@ public class SofaMultiParamServiceImpl implements SofaMultiParamService {
     }
 
     @Override
-    @ShenyuSofaClient(path = "/saveTwoList", desc = "saveTwoList")
+    @ShenyuSofaClient("/saveTwoList")
     public SofaSimpleTypeBean saveTwoList(final List<SofaComplexTypeBean> sofaComplexTypeBeanList, final Map<String, SofaSimpleTypeBean> sofaSimpleTypeBeanMap) {
         SofaSimpleTypeBean simpleTypeBean = new SofaSimpleTypeBean();
         if (!CollectionUtils.isEmpty(sofaComplexTypeBeanList) && !CollectionUtils.isEmpty(sofaSimpleTypeBeanMap)) {
diff --git a/shenyu-examples/shenyu-examples-sofa/shenyu-examples-sofa-service/src/main/java/org/apache/shenyu/examples/sofa/service/impl/SofaSingleParamServiceImpl.java b/shenyu-examples/shenyu-examples-sofa/shenyu-examples-sofa-service/src/main/java/org/apache/shenyu/examples/sofa/service/impl/SofaSingleParamServiceImpl.java
index 2a7a4bc8f..7e266aaf0 100644
--- a/shenyu-examples/shenyu-examples-sofa/shenyu-examples-sofa-service/src/main/java/org/apache/shenyu/examples/sofa/service/impl/SofaSingleParamServiceImpl.java
+++ b/shenyu-examples/shenyu-examples-sofa/shenyu-examples-sofa-service/src/main/java/org/apache/shenyu/examples/sofa/service/impl/SofaSingleParamServiceImpl.java
@@ -31,19 +31,19 @@ import java.util.Random;
 public class SofaSingleParamServiceImpl implements SofaSingleParamService {
 
     @Override
-    @ShenyuSofaClient(path = "/findById", desc = "Find by Id")
+    @ShenyuSofaClient("/findById")
     public SofaSimpleTypeBean findById(final String id) {
         return new SofaSimpleTypeBean(id, "hello world shenyu Sofa, findById");
     }
 
     @Override
-    @ShenyuSofaClient(path = "/findAll", desc = "Get all data")
+    @ShenyuSofaClient("/findAll")
     public SofaSimpleTypeBean findAll() {
         return new SofaSimpleTypeBean(String.valueOf(new Random().nextInt()), "hello world shenyu Sofa , findAll");
     }
 
     @Override
-    @ShenyuSofaClient(path = "/insert", desc = "Insert a row of data")
+    @ShenyuSofaClient("/insert")
     public SofaSimpleTypeBean insert(final SofaSimpleTypeBean sofaSimpleTypeBean) {
         sofaSimpleTypeBean.setName("hello world shenyu Sofa: " + sofaSimpleTypeBean.getName());
         return sofaSimpleTypeBean;