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/10 13:46:59 UTC
[incubator-shenyu] branch master updated: [ISSUE 3485] sub task5 @AliasFor for @ShenyuMotanClient (#3519)
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 75f2a57c2 [ISSUE 3485] sub task5 @AliasFor for @ShenyuMotanClient (#3519)
75f2a57c2 is described below
commit 75f2a57c2f5a0e878253bfd978f0f57fd2de04ae
Author: ChineseTony <ta...@163.com>
AuthorDate: Fri Jun 10 21:46:53 2022 +0800
[ISSUE 3485] sub task5 @AliasFor for @ShenyuMotanClient (#3519)
* sub task5 @AliasFor for @ShenyuMotanClient
---
.../shenyu/client/motan/MotanServiceBeanPostProcessor.java | 8 ++++----
.../client/motan/common/annotation/ShenyuMotanClient.java | 13 ++++++++++++-
.../examples/motan/service/impl/MotanDemoServiceImpl.java | 6 +++---
3 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/shenyu-client/shenyu-client-motan/src/main/java/org/apache/shenyu/client/motan/MotanServiceBeanPostProcessor.java b/shenyu-client/shenyu-client-motan/src/main/java/org/apache/shenyu/client/motan/MotanServiceBeanPostProcessor.java
index db0d7e8a4..9142e12d4 100644
--- a/shenyu-client/shenyu-client-motan/src/main/java/org/apache/shenyu/client/motan/MotanServiceBeanPostProcessor.java
+++ b/shenyu-client/shenyu-client-motan/src/main/java/org/apache/shenyu/client/motan/MotanServiceBeanPostProcessor.java
@@ -39,7 +39,7 @@ import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
-import org.springframework.core.annotation.AnnotationUtils;
+import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.lang.NonNull;
import org.springframework.util.ReflectionUtils;
@@ -122,7 +122,7 @@ public class MotanServiceBeanPostProcessor implements BeanPostProcessor, Applica
}
String superPath = buildApiSuperPath(clazz);
MotanService service = clazz.getAnnotation(MotanService.class);
- ShenyuMotanClient beanShenyuClient = AnnotationUtils.findAnnotation(clazz, ShenyuMotanClient.class);
+ ShenyuMotanClient beanShenyuClient = AnnotatedElementUtils.findMergedAnnotation(clazz, ShenyuMotanClient.class);
if (superPath.contains("*")) {
Method[] methods = ReflectionUtils.getDeclaredMethods(clazz);
for (Method method : methods) {
@@ -135,7 +135,7 @@ public class MotanServiceBeanPostProcessor implements BeanPostProcessor, Applica
}
Method[] methods = ReflectionUtils.getUniqueDeclaredMethods(clazz);
for (Method method : methods) {
- ShenyuMotanClient shenyuMotanClient = method.getAnnotation(ShenyuMotanClient.class);
+ ShenyuMotanClient shenyuMotanClient = AnnotatedElementUtils.findMergedAnnotation(method, ShenyuMotanClient.class);
if (Objects.nonNull(shenyuMotanClient)) {
publisher.publishEvent(buildMetaDataDTO(clazz, service,
shenyuMotanClient, method, buildRpcExt(method, timeout), superPath));
@@ -205,7 +205,7 @@ public class MotanServiceBeanPostProcessor implements BeanPostProcessor, Applica
}
private String buildApiSuperPath(@NonNull final Class<?> clazz) {
- ShenyuMotanClient shenyuMotanClient = AnnotationUtils.findAnnotation(clazz, ShenyuMotanClient.class);
+ ShenyuMotanClient shenyuMotanClient = AnnotatedElementUtils.findMergedAnnotation(clazz, ShenyuMotanClient.class);
if (Objects.nonNull(shenyuMotanClient) && StringUtils.isNotBlank(shenyuMotanClient.path())) {
return shenyuMotanClient.path();
}
diff --git a/shenyu-client/shenyu-client-motan/src/main/java/org/apache/shenyu/client/motan/common/annotation/ShenyuMotanClient.java b/shenyu-client/shenyu-client-motan/src/main/java/org/apache/shenyu/client/motan/common/annotation/ShenyuMotanClient.java
index 0a8a3fa26..9be0ef1cc 100644
--- a/shenyu-client/shenyu-client-motan/src/main/java/org/apache/shenyu/client/motan/common/annotation/ShenyuMotanClient.java
+++ b/shenyu-client/shenyu-client-motan/src/main/java/org/apache/shenyu/client/motan/common/annotation/ShenyuMotanClient.java
@@ -17,6 +17,8 @@
package org.apache.shenyu.client.motan.common.annotation;
+import org.springframework.core.annotation.AliasFor;
+
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
@@ -30,13 +32,22 @@ import java.lang.annotation.Target;
@Target({ElementType.TYPE, ElementType.METHOD})
@Inherited
public @interface ShenyuMotanClient {
+
/**
* Path string.
*
* @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-motan/shenyu-examples-motan-service/src/main/java/org/apache/shenyu/examples/motan/service/impl/MotanDemoServiceImpl.java b/shenyu-examples/shenyu-examples-motan/shenyu-examples-motan-service/src/main/java/org/apache/shenyu/examples/motan/service/impl/MotanDemoServiceImpl.java
index 8c0bb388b..2598d0b4d 100644
--- a/shenyu-examples/shenyu-examples-motan/shenyu-examples-motan-service/src/main/java/org/apache/shenyu/examples/motan/service/impl/MotanDemoServiceImpl.java
+++ b/shenyu-examples/shenyu-examples-motan/shenyu-examples-motan-service/src/main/java/org/apache/shenyu/examples/motan/service/impl/MotanDemoServiceImpl.java
@@ -25,17 +25,17 @@ import org.apache.shenyu.examples.motan.service.MotanDemoService;
* Motan demo service.
*/
@MotanService(export = "demoMotan:8002")
-@ShenyuMotanClient(path = "/demo/**")
+@ShenyuMotanClient("/demo/**")
public class MotanDemoServiceImpl implements MotanDemoService {
@Override
- @ShenyuMotanClient(path = "/hello")
+ @ShenyuMotanClient("/hello")
public String hello(final String name) {
return "hello " + name;
}
@Override
- @ShenyuMotanClient(path = "/timeout")
+ @ShenyuMotanClient("/timeout")
public String testTimeOut(final String timeout) {
try {
Thread.sleep((long) (Double.parseDouble(timeout) * 1000));