You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by li...@apache.org on 2022/06/11 02:58:33 UTC
[incubator-shenyu] branch master updated: simplify ShenyuTarsClient (#3528)
This is an automated email from the ASF dual-hosted git repository.
likeguo 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 336d939ac simplify ShenyuTarsClient (#3528)
336d939ac is described below
commit 336d939ac0d5ef4b0c6880fa51538a41128e6189
Author: weihubeats <we...@163.com>
AuthorDate: Sat Jun 11 10:58:27 2022 +0800
simplify ShenyuTarsClient (#3528)
---
.../shenyu/client/tars/TarsServiceBeanPostProcessor.java | 10 +++++++---
.../client/tars/common/annotation/ShenyuTarsClient.java | 14 +++++++++++++-
.../client/tars/TarsServiceBeanPostProcessorTest.java | 2 +-
.../tars/servant/testapp/impl/HelloServantImpl.java | 4 ++--
4 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/shenyu-client/shenyu-client-tars/src/main/java/org/apache/shenyu/client/tars/TarsServiceBeanPostProcessor.java b/shenyu-client/shenyu-client-tars/src/main/java/org/apache/shenyu/client/tars/TarsServiceBeanPostProcessor.java
index 4e85cbbce..d4c625895 100644
--- a/shenyu-client/shenyu-client-tars/src/main/java/org/apache/shenyu/client/tars/TarsServiceBeanPostProcessor.java
+++ b/shenyu-client/shenyu-client-tars/src/main/java/org/apache/shenyu/client/tars/TarsServiceBeanPostProcessor.java
@@ -20,8 +20,8 @@ package org.apache.shenyu.client.tars;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.shenyu.client.core.constant.ShenyuClientConstants;
-import org.apache.shenyu.client.core.exception.ShenyuClientIllegalArgumentException;
import org.apache.shenyu.client.core.disruptor.ShenyuClientRegisterEventPublisher;
+import org.apache.shenyu.client.core.exception.ShenyuClientIllegalArgumentException;
import org.apache.shenyu.client.tars.common.annotation.ShenyuTarsClient;
import org.apache.shenyu.client.tars.common.annotation.ShenyuTarsService;
import org.apache.shenyu.client.tars.common.dto.TarsRpcExt;
@@ -35,7 +35,7 @@ import org.springframework.aop.support.AopUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
-import org.springframework.core.annotation.AnnotationUtils;
+import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.util.ReflectionUtils;
import java.lang.reflect.Method;
@@ -79,7 +79,11 @@ public class TarsServiceBeanPostProcessor implements BeanPostProcessor {
@Override
public Object postProcessAfterInitialization(final Object bean, final String beanName) throws BeansException {
- if (AnnotationUtils.findAnnotation(bean.getClass(), ShenyuTarsService.class) != null) {
+ Class clazz = bean.getClass();
+ if (AopUtils.isAopProxy(clazz)) {
+ clazz = AopUtils.getTargetClass(clazz);
+ }
+ if (AnnotatedElementUtils.findMergedAnnotation(clazz, ShenyuTarsService.class) != null) {
handler(bean);
}
return bean;
diff --git a/shenyu-client/shenyu-client-tars/src/main/java/org/apache/shenyu/client/tars/common/annotation/ShenyuTarsClient.java b/shenyu-client/shenyu-client-tars/src/main/java/org/apache/shenyu/client/tars/common/annotation/ShenyuTarsClient.java
index a123fda80..d3f6a5af0 100644
--- a/shenyu-client/shenyu-client-tars/src/main/java/org/apache/shenyu/client/tars/common/annotation/ShenyuTarsClient.java
+++ b/shenyu-client/shenyu-client-tars/src/main/java/org/apache/shenyu/client/tars/common/annotation/ShenyuTarsClient.java
@@ -17,6 +17,8 @@
package org.apache.shenyu.client.tars.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 ShenyuTarsClient {
+
+ /**
+ * 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-client/shenyu-client-tars/src/test/java/org/apache/shenyu/client/tars/TarsServiceBeanPostProcessorTest.java b/shenyu-client/shenyu-client-tars/src/test/java/org/apache/shenyu/client/tars/TarsServiceBeanPostProcessorTest.java
index f12009de3..a95b7875e 100644
--- a/shenyu-client/shenyu-client-tars/src/test/java/org/apache/shenyu/client/tars/TarsServiceBeanPostProcessorTest.java
+++ b/shenyu-client/shenyu-client-tars/src/test/java/org/apache/shenyu/client/tars/TarsServiceBeanPostProcessorTest.java
@@ -83,7 +83,7 @@ public final class TarsServiceBeanPostProcessorTest {
@ShenyuTarsService(serviceName = "testObj")
static class TarsDemoService {
- @ShenyuTarsClient(path = "hello")
+ @ShenyuTarsClient("hello")
public String test(final String hello) {
return hello + "";
}
diff --git a/shenyu-examples/shenyu-examples-tars/src/main/java/org/apache/shenyu/examples/tars/servant/testapp/impl/HelloServantImpl.java b/shenyu-examples/shenyu-examples-tars/src/main/java/org/apache/shenyu/examples/tars/servant/testapp/impl/HelloServantImpl.java
index 9791163da..cce8f460b 100644
--- a/shenyu-examples/shenyu-examples-tars/src/main/java/org/apache/shenyu/examples/tars/servant/testapp/impl/HelloServantImpl.java
+++ b/shenyu-examples/shenyu-examples-tars/src/main/java/org/apache/shenyu/examples/tars/servant/testapp/impl/HelloServantImpl.java
@@ -28,14 +28,14 @@ import org.apache.shenyu.examples.tars.servant.testapp.HelloServant;
public class HelloServantImpl implements HelloServant {
@Override
- @ShenyuTarsClient(path = "/hello", desc = "hello")
+ @ShenyuTarsClient("/hello")
public String hello(final int no, final String name) {
return String.format("hello no=%s, name=%s, time=%s", no, name, System.currentTimeMillis());
}
@Log
@Override
- @ShenyuTarsClient(path = "/helloInt", desc = "helloInt")
+ @ShenyuTarsClient("/helloInt")
public int helloInt(final int no, final String name) {
return 1;
}