You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2022/05/07 06:00:54 UTC

[dubbo] branch 3.0 updated: [3.0]fix #9863, @Method annotation parma isReturn invalid (#9865)

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

liujun pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.0 by this push:
     new a2f1650526 [3.0]fix #9863, @Method annotation parma isReturn invalid (#9865)
a2f1650526 is described below

commit a2f165052661bbdcf7c97b04e7be7cf7ee1ccffd
Author: Wang Chengming <63...@qq.com>
AuthorDate: Sat May 7 14:00:06 2022 +0800

    [3.0]fix #9863, @Method annotation parma isReturn invalid (#9865)
---
 .../java/org/apache/dubbo/config/MethodConfig.java |  2 +-
 .../config/spring/reference/ReferenceCreator.java  | 12 +++-
 .../factory/annotation/ReferenceCreatorTest.java   | 70 +++++++++++-----------
 3 files changed, 46 insertions(+), 38 deletions(-)

diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/MethodConfig.java b/dubbo-common/src/main/java/org/apache/dubbo/config/MethodConfig.java
index 80020e28c6..d8696fadc4 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/config/MethodConfig.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/config/MethodConfig.java
@@ -177,7 +177,7 @@ public class MethodConfig extends AbstractMethodConfig {
         }
 
         if (method.arguments() != null && method.arguments().length != 0) {
-            List<ArgumentConfig> argumentConfigs = new ArrayList<ArgumentConfig>(method.arguments().length);
+            List<ArgumentConfig> argumentConfigs = new ArrayList<>(method.arguments().length);
             this.setArguments(argumentConfigs);
             for (int i = 0; i < method.arguments().length; i++) {
                 ArgumentConfig argumentConfig = new ArgumentConfig(method.arguments()[i]);
diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/reference/ReferenceCreator.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/reference/ReferenceCreator.java
index 4d7493e772..d8b1aed9b3 100644
--- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/reference/ReferenceCreator.java
+++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/reference/ReferenceCreator.java
@@ -57,8 +57,13 @@ public class ReferenceCreator {
     static final String[] IGNORE_FIELD_NAMES = of("application", "module", "consumer", "monitor", "registry", "interfaceClass");
 
     private static final String ONRETURN = "onreturn";
+
     private static final String ONTHROW = "onthrow";
+
     private static final String ONINVOKE = "oninvoke";
+
+    private static final String ISRETURN = "isReturn";
+
     private static final String METHOD = "Method";
 
     protected final Log logger = LogFactory.getLog(getClass());
@@ -78,7 +83,7 @@ public class ReferenceCreator {
         this.attributes = attributes;
         this.applicationContext = applicationContext;
         this.classLoader = applicationContext.getClassLoader() != null ?
-                applicationContext.getClassLoader() : Thread.currentThread().getContextClassLoader();
+            applicationContext.getClassLoader() : Thread.currentThread().getContextClassLoader();
         moduleModel = DubboBeanUtils.getModuleModel(applicationContext);
         Assert.notNull(moduleModel, "ModuleModel not found in Spring ApplicationContext");
     }
@@ -145,7 +150,7 @@ public class ReferenceCreator {
             } else if (consumer instanceof ConsumerConfig) {
                 consumerConfig = (ConsumerConfig) consumer;
             } else {
-                throw new IllegalArgumentException("Unexpected 'consumer' attribute value: "+consumer);
+                throw new IllegalArgumentException("Unexpected 'consumer' attribute value: " + consumer);
             }
             referenceBean.setConsumer(consumerConfig);
         }
@@ -226,7 +231,7 @@ public class ReferenceCreator {
                     String beanName = strValue.substring(0, index);
                     String methodName = strValue.substring(index + 1);
                     methodAttributes.put(callbackName, applicationContext.getBean(beanName));
-                    methodAttributes.put(callbackName+METHOD, methodName);
+                    methodAttributes.put(callbackName + METHOD, methodName);
                 } else {
                     methodAttributes.put(callbackName, applicationContext.getBean(strValue));
                 }
@@ -235,6 +240,7 @@ public class ReferenceCreator {
 
         MethodConfig methodConfig = new MethodConfig();
         DataBinder mcDataBinder = new DataBinder(methodConfig);
+        methodConfig.setReturn((Boolean) methodAttributes.get(ISRETURN));
         mcDataBinder.setConversionService(conversionService);
         AnnotationPropertyValuesAdapter propertyValues = new AnnotationPropertyValuesAdapter(methodAttributes, applicationContext.getEnvironment());
         mcDataBinder.bind(propertyValues);
diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceCreatorTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceCreatorTest.java
index a5d785f036..0db3ce4ea8 100644
--- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceCreatorTest.java
+++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceCreatorTest.java
@@ -77,35 +77,36 @@ public class ReferenceCreatorTest {
     private static final String REGISTRY_CONFIG_ID = "myregistry";
 
     @DubboReference(
-            //interfaceClass = HelloService.class,
-            version = "1.0.0", group = "TEST_GROUP", url = "dubbo://localhost:12345",
-            client = "client", generic = false, injvm = false,
-            check = false, init = false, lazy = true,
-            stubevent = true, reconnect = "reconnect", sticky = true,
-            proxy = "javassist", stub = "org.apache.dubbo.config.spring.api.HelloService", cluster = "failover",
-            connections = 3, callbacks = 1, onconnect = "onconnect", ondisconnect = "ondisconnect",
-            owner = "owner", layer = "layer", retries = 1,
-            loadbalance = "random", async = true, actives = 3,
-            sent = true, mock = "mock", validation = "validation",
-            timeout = 3, cache = "cache", filter = {"echo", "generic", "accesslog"},
-            listener = {"deprecated"}, parameters = {"n1=v1  ", "n2 = v2 ", "  n3 =   v3  "},
-            application = "application",
-            module = MODULE_CONFIG_ID, consumer = CONSUMER_CONFIG_ID, monitor = MONITOR_CONFIG_ID, registry = {REGISTRY_CONFIG_ID},
-            // @since 2.7.3
-            id = "reference",
-            // @since 2.7.8
-            services = {"service1", "service2", "service3", "service2", "service1"},
-            providedBy = {"service1", "service2", "service3"},
-            methods = @Method(name = "sayHello",
-                    loadbalance = "loadbalance",
-                    oninvoke = "notifyService.onInvoke",
-                    onreturn = "notifyService.onReturn",
-                    onthrow = "notifyService.onThrow",
-                    timeout = 1000,
-                    retries = 2,
-                    parameters = {"a", "1", "b", "2"},
-                    arguments = @Argument(index = 0, callback = true)
-            )
+        //interfaceClass = HelloService.class,
+        version = "1.0.0", group = "TEST_GROUP", url = "dubbo://localhost:12345",
+        client = "client", generic = false, injvm = false,
+        check = false, init = false, lazy = true,
+        stubevent = true, reconnect = "reconnect", sticky = true,
+        proxy = "javassist", stub = "org.apache.dubbo.config.spring.api.HelloService", cluster = "failover",
+        connections = 3, callbacks = 1, onconnect = "onconnect", ondisconnect = "ondisconnect",
+        owner = "owner", layer = "layer", retries = 1,
+        loadbalance = "random", async = true, actives = 3,
+        sent = true, mock = "mock", validation = "validation",
+        timeout = 3, cache = "cache", filter = {"echo", "generic", "accesslog"},
+        listener = {"deprecated"}, parameters = {"n1=v1  ", "n2 = v2 ", "  n3 =   v3  "},
+        application = "application",
+        module = MODULE_CONFIG_ID, consumer = CONSUMER_CONFIG_ID, monitor = MONITOR_CONFIG_ID, registry = {REGISTRY_CONFIG_ID},
+        // @since 2.7.3
+        id = "reference",
+        // @since 2.7.8
+        services = {"service1", "service2", "service3", "service2", "service1"},
+        providedBy = {"service1", "service2", "service3"},
+        methods = @Method(name = "sayHello",
+            isReturn = false,
+            loadbalance = "loadbalance",
+            oninvoke = "notifyService.onInvoke",
+            onreturn = "notifyService.onReturn",
+            onthrow = "notifyService.onThrow",
+            timeout = 1000,
+            retries = 2,
+            parameters = {"a", "1", "b", "2"},
+            arguments = @Argument(index = 0, callback = true)
+        )
     )
     private HelloService helloService;
 
@@ -128,8 +129,8 @@ public class ReferenceCreatorTest {
         // filter default value
         AnnotationAttributes attributes = AnnotationUtils.getAnnotationAttributes(reference, true);
         ReferenceConfig referenceBean = ReferenceCreator.create(attributes, context)
-                .defaultInterfaceClass(helloServiceField.getType())
-                .build();
+            .defaultInterfaceClass(helloServiceField.getType())
+            .build();
         Assertions.assertEquals(HelloService.class, referenceBean.getInterfaceClass());
         Assertions.assertEquals("org.apache.dubbo.config.spring.api.HelloService", referenceBean.getInterface());
         Assertions.assertEquals("1.0.0", referenceBean.getVersion());
@@ -182,6 +183,7 @@ public class ReferenceCreatorTest {
         Assertions.assertEquals(1, methods.size());
         MethodConfig methodConfig = methods.get(0);
         Assertions.assertEquals("sayHello", methodConfig.getName());
+        Assertions.assertEquals(false, methodConfig.isReturn());
         Assertions.assertEquals(1000, methodConfig.getTimeout());
         Assertions.assertEquals(2, methodConfig.getRetries());
         Assertions.assertEquals("loadbalance", methodConfig.getLoadbalance());
@@ -205,7 +207,7 @@ public class ReferenceCreatorTest {
         Assertions.assertEquals(true, argumentConfig.isCallback());
 
         // Asserts Null fields
-        Assertions.assertThrows(IllegalStateException.class, () -> referenceBean.getApplication());
+        Assertions.assertThrows(IllegalStateException.class, referenceBean::getApplication);
         Assertions.assertNotNull(referenceBean.getModule());
         Assertions.assertNotNull(referenceBean.getConsumer());
         Assertions.assertNotNull(referenceBean.getMonitor());
@@ -231,12 +233,12 @@ public class ReferenceCreatorTest {
         }
 
         @Bean(MONITOR_CONFIG_ID)
-        public MonitorConfig monitorConfig(){
+        public MonitorConfig monitorConfig() {
             return new MonitorConfig();
         }
 
         @Bean(MODULE_CONFIG_ID)
-        public ModuleConfig moduleConfig(){
+        public ModuleConfig moduleConfig() {
             return new ModuleConfig();
         }