From 2fd0bb40c5f9a2f8fba7f02eedd1f1c027504489 Mon Sep 17 00:00:00 2001 From: alphacba Date: Sat, 1 Sep 2018 10:47:16 +0800 Subject: [PATCH 1/6] add getter and setter for ServiceConfig's interfaceName property#2353 --- .../apache/dubbo/config/ServiceConfig.java | 8 +++++ .../dubbo/config/spring/ConfigTest.java | 14 ++++++++ .../impl/DemoServiceAnnotationImpl.java | 34 +++++++++++++++++++ .../config/spring/service-annotation.xml | 32 +++++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/DemoServiceAnnotationImpl.java create mode 100644 dubbo-config/dubbo-config-spring/src/test/resources/org/apache/dubbo/config/spring/service-annotation.xml diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java index e9d5e6b5671..2e30b56b629 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java @@ -851,4 +851,12 @@ public String getUniqueServiceName() { } return buf.toString(); } + + public String getInterfaceName() { + return interfaceName; + } + + public void setInterfaceName(String interfaceName) { + this.interfaceName = interfaceName; + } } diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java index 5698277bdd8..cede834ed35 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java @@ -105,6 +105,20 @@ public void testServiceClass() { } } + @Test + public void testServiceAnnotation() { + ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/service-annotation.xml"); + ctx.start(); + try { + DemoService demoService = refer("dubbo://127.0.0.1:20887"); + String hello = demoService.sayName("hello"); + assertEquals("say:hello", hello); + } finally { + ctx.stop(); + ctx.close(); + } + } + @Test @SuppressWarnings("unchecked") public void testProviderNestedService() { diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/DemoServiceAnnotationImpl.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/DemoServiceAnnotationImpl.java new file mode 100644 index 00000000000..0c97537bf13 --- /dev/null +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/DemoServiceAnnotationImpl.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.dubbo.config.spring.impl; + +import org.apache.dubbo.config.annotation.Service; +import org.apache.dubbo.config.spring.api.Box; +import org.apache.dubbo.config.spring.api.DemoService; + +@Service(interfaceName = "org.apache.dubbo.config.spring.api.DemoService") +public class DemoServiceAnnotationImpl implements DemoService { + @Override + public String sayName(String name) { + return "say:" + name; + } + + @Override + public Box getBox() { + return null; + } +} diff --git a/dubbo-config/dubbo-config-spring/src/test/resources/org/apache/dubbo/config/spring/service-annotation.xml b/dubbo-config/dubbo-config-spring/src/test/resources/org/apache/dubbo/config/spring/service-annotation.xml new file mode 100644 index 00000000000..83f9f9e62aa --- /dev/null +++ b/dubbo-config/dubbo-config-spring/src/test/resources/org/apache/dubbo/config/spring/service-annotation.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + \ No newline at end of file From 4e0a0bca1069801f505493f40dcc6667f7778e18 Mon Sep 17 00:00:00 2001 From: alphacba Date: Fri, 7 Sep 2018 13:23:12 +0800 Subject: [PATCH 2/6] add interfaceName to ignoreAttributeNames and change the unit test --- .../main/java/org/apache/dubbo/config/ServiceConfig.java | 7 ------- .../annotation/ServiceAnnotationBeanPostProcessor.java | 2 +- .../config/spring/impl/DemoServiceAnnotationImpl.java | 8 +++++++- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java index 2e30b56b629..583cb103695 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java @@ -852,11 +852,4 @@ public String getUniqueServiceName() { return buf.toString(); } - public String getInterfaceName() { - return interfaceName; - } - - public void setInterfaceName(String interfaceName) { - this.interfaceName = interfaceName; - } } diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationBeanPostProcessor.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationBeanPostProcessor.java index 389ef217367..fa212d8e183 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationBeanPostProcessor.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationBeanPostProcessor.java @@ -386,7 +386,7 @@ private AbstractBeanDefinition buildServiceBeanDefinition(Service service, Class MutablePropertyValues propertyValues = beanDefinition.getPropertyValues(); - String[] ignoreAttributeNames = of("provider", "monitor", "application", "module", "registry", "protocol", "interface"); + String[] ignoreAttributeNames = of("provider", "monitor", "application", "module", "registry", "protocol", "interface", "interfaceName"); propertyValues.addPropertyValues(new AnnotationPropertyValuesAdapter(service, environment, ignoreAttributeNames)); diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/DemoServiceAnnotationImpl.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/DemoServiceAnnotationImpl.java index 0c97537bf13..48948d538f7 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/DemoServiceAnnotationImpl.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/DemoServiceAnnotationImpl.java @@ -19,9 +19,10 @@ import org.apache.dubbo.config.annotation.Service; import org.apache.dubbo.config.spring.api.Box; import org.apache.dubbo.config.spring.api.DemoService; +import org.apache.dubbo.config.spring.api.HelloService; @Service(interfaceName = "org.apache.dubbo.config.spring.api.DemoService") -public class DemoServiceAnnotationImpl implements DemoService { +public class DemoServiceAnnotationImpl implements HelloService, DemoService { @Override public String sayName(String name) { return "say:" + name; @@ -31,4 +32,9 @@ public String sayName(String name) { public Box getBox() { return null; } + + @Override + public String sayHello(String name) { + return "say hello:" + name; + } } From cd46b4fb5f2c539618cfadce448703ea5bc99f23 Mon Sep 17 00:00:00 2001 From: alphacba Date: Fri, 7 Sep 2018 14:27:11 +0800 Subject: [PATCH 3/6] delete the demo source code and update the unit test --- .../dubbo/config/spring/ConfigTest.java | 12 ++++-- .../impl/DemoServiceAnnotationImpl.java | 40 ------------------- .../config/spring/impl/HelloServiceImpl.java | 3 ++ .../config/spring/service-annotation.xml | 32 --------------- .../dubbo/config/spring/service-class.xml | 1 + 5 files changed, 12 insertions(+), 76 deletions(-) delete mode 100644 dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/DemoServiceAnnotationImpl.java delete mode 100644 dubbo-config/dubbo-config-spring/src/test/resources/org/apache/dubbo/config/spring/service-annotation.xml diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java index cede834ed35..83add22cf98 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java @@ -107,12 +107,16 @@ public void testServiceClass() { @Test public void testServiceAnnotation() { - ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/service-annotation.xml"); + ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/service-class.xml"); ctx.start(); try { - DemoService demoService = refer("dubbo://127.0.0.1:20887"); - String hello = demoService.sayName("hello"); - assertEquals("say:hello", hello); + ReferenceConfig reference = new ReferenceConfig(); + reference.setApplication(new ApplicationConfig("consumer")); + reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE)); + reference.setInterface(HelloService.class); + reference.setUrl("dubbo://127.0.0.1:20887"); + String hello = reference.get().sayHello("hello"); + assertEquals("Hello, hello", hello); } finally { ctx.stop(); ctx.close(); diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/DemoServiceAnnotationImpl.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/DemoServiceAnnotationImpl.java deleted file mode 100644 index 48948d538f7..00000000000 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/DemoServiceAnnotationImpl.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.dubbo.config.spring.impl; - -import org.apache.dubbo.config.annotation.Service; -import org.apache.dubbo.config.spring.api.Box; -import org.apache.dubbo.config.spring.api.DemoService; -import org.apache.dubbo.config.spring.api.HelloService; - -@Service(interfaceName = "org.apache.dubbo.config.spring.api.DemoService") -public class DemoServiceAnnotationImpl implements HelloService, DemoService { - @Override - public String sayName(String name) { - return "say:" + name; - } - - @Override - public Box getBox() { - return null; - } - - @Override - public String sayHello(String name) { - return "say hello:" + name; - } -} diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/HelloServiceImpl.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/HelloServiceImpl.java index b4eacb4bd78..bf18407c86c 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/HelloServiceImpl.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/HelloServiceImpl.java @@ -16,8 +16,11 @@ */ package org.apache.dubbo.config.spring.impl; +import org.apache.dubbo.config.annotation.Service; import org.apache.dubbo.config.spring.api.HelloService; + +@Service(interfaceName = "org.apache.dubbo.config.spring.api.HelloService") public class HelloServiceImpl implements HelloService { public String sayHello(String name) { diff --git a/dubbo-config/dubbo-config-spring/src/test/resources/org/apache/dubbo/config/spring/service-annotation.xml b/dubbo-config/dubbo-config-spring/src/test/resources/org/apache/dubbo/config/spring/service-annotation.xml deleted file mode 100644 index 83f9f9e62aa..00000000000 --- a/dubbo-config/dubbo-config-spring/src/test/resources/org/apache/dubbo/config/spring/service-annotation.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/dubbo-config/dubbo-config-spring/src/test/resources/org/apache/dubbo/config/spring/service-class.xml b/dubbo-config/dubbo-config-spring/src/test/resources/org/apache/dubbo/config/spring/service-class.xml index 548e360e80e..27d4953e4c9 100644 --- a/dubbo-config/dubbo-config-spring/src/test/resources/org/apache/dubbo/config/spring/service-class.xml +++ b/dubbo-config/dubbo-config-spring/src/test/resources/org/apache/dubbo/config/spring/service-class.xml @@ -32,5 +32,6 @@ class="org.apache.dubbo.config.spring.impl.DemoServiceImpl"> + \ No newline at end of file From 9fecd6b3d8231f8f41d2c7dda71bccf4b352977e Mon Sep 17 00:00:00 2001 From: alphacba Date: Fri, 7 Sep 2018 15:49:39 +0800 Subject: [PATCH 4/6] unchange ServiceConfig --- .../src/main/java/org/apache/dubbo/config/ServiceConfig.java | 1 - 1 file changed, 1 deletion(-) diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java index 583cb103695..e9d5e6b5671 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java @@ -851,5 +851,4 @@ public String getUniqueServiceName() { } return buf.toString(); } - } From 50729a72aedd0de6bf3316c9254eb52db69fe5cb Mon Sep 17 00:00:00 2001 From: alphacba Date: Mon, 10 Sep 2018 22:20:33 +0800 Subject: [PATCH 5/6] update unit test --- .../dubbo/config/spring/ConfigTest.java | 30 ++++++++++--------- .../annotation/provider/HelloServiceImpl.java | 2 +- .../config/spring/impl/HelloServiceImpl.java | 3 -- .../dubbo/config/spring/service-class.xml | 1 - 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java index 83add22cf98..c4084173f1a 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java @@ -33,6 +33,7 @@ import org.apache.dubbo.config.spring.annotation.consumer.AnnotationAction; import org.apache.dubbo.config.spring.api.DemoService; import org.apache.dubbo.config.spring.api.HelloService; +import org.apache.dubbo.config.spring.context.annotation.provider.ProviderConfiguration; import org.apache.dubbo.config.spring.filter.MockFilter; import org.apache.dubbo.config.spring.impl.DemoServiceImpl; import org.apache.dubbo.config.spring.impl.HelloServiceImpl; @@ -50,6 +51,7 @@ import org.junit.Ignore; import org.junit.Test; import org.springframework.beans.factory.BeanCreationException; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import java.util.Collection; @@ -107,20 +109,19 @@ public void testServiceClass() { @Test public void testServiceAnnotation() { - ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/service-class.xml"); - ctx.start(); - try { - ReferenceConfig reference = new ReferenceConfig(); - reference.setApplication(new ApplicationConfig("consumer")); - reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE)); - reference.setInterface(HelloService.class); - reference.setUrl("dubbo://127.0.0.1:20887"); - String hello = reference.get().sayHello("hello"); - assertEquals("Hello, hello", hello); - } finally { - ctx.stop(); - ctx.close(); - } + AnnotationConfigApplicationContext providerContext = new AnnotationConfigApplicationContext(); + providerContext.register(ProviderConfiguration.class); + + providerContext.refresh(); + + ReferenceConfig reference = new ReferenceConfig(); + reference.setApplication(new ApplicationConfig("consumer")); + reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE)); + reference.setInterface(HelloService.class); + reference.setUrl("dubbo://127.0.0.1:12345"); + String hello = reference.get().sayHello("hello"); + assertEquals("Hello, hello", hello); + } @Test @@ -834,6 +835,7 @@ public void testPath() throws Exception { public void testAnnotation() { SimpleRegistryService registryService = new SimpleRegistryService(); Exporter exporter = SimpleRegistryExporter.export(4548, registryService); + System.setProperty("provider.version", "1.0"); try { ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/annotation-provider.xml"); providerContext.start(); diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/provider/HelloServiceImpl.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/provider/HelloServiceImpl.java index 1c4b405a90a..982e52a3f73 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/provider/HelloServiceImpl.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/provider/HelloServiceImpl.java @@ -24,7 +24,7 @@ * * @since 2.5.9 */ -@Service +@Service(interfaceName = "org.apache.dubbo.config.spring.api.HelloService") public class HelloServiceImpl implements HelloService { @Override diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/HelloServiceImpl.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/HelloServiceImpl.java index bf18407c86c..b4eacb4bd78 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/HelloServiceImpl.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/HelloServiceImpl.java @@ -16,11 +16,8 @@ */ package org.apache.dubbo.config.spring.impl; -import org.apache.dubbo.config.annotation.Service; import org.apache.dubbo.config.spring.api.HelloService; - -@Service(interfaceName = "org.apache.dubbo.config.spring.api.HelloService") public class HelloServiceImpl implements HelloService { public String sayHello(String name) { diff --git a/dubbo-config/dubbo-config-spring/src/test/resources/org/apache/dubbo/config/spring/service-class.xml b/dubbo-config/dubbo-config-spring/src/test/resources/org/apache/dubbo/config/spring/service-class.xml index 27d4953e4c9..548e360e80e 100644 --- a/dubbo-config/dubbo-config-spring/src/test/resources/org/apache/dubbo/config/spring/service-class.xml +++ b/dubbo-config/dubbo-config-spring/src/test/resources/org/apache/dubbo/config/spring/service-class.xml @@ -32,6 +32,5 @@ class="org.apache.dubbo.config.spring.impl.DemoServiceImpl"> - \ No newline at end of file From 3cfb36eb02334d0187d2b14fcda277726afc95fe Mon Sep 17 00:00:00 2001 From: alphacba Date: Mon, 10 Sep 2018 22:25:12 +0800 Subject: [PATCH 6/6] update unit test --- .../src/test/java/org/apache/dubbo/config/spring/ConfigTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java index c4084173f1a..12a9354dd35 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java @@ -835,7 +835,6 @@ public void testPath() throws Exception { public void testAnnotation() { SimpleRegistryService registryService = new SimpleRegistryService(); Exporter exporter = SimpleRegistryExporter.export(4548, registryService); - System.setProperty("provider.version", "1.0"); try { ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/annotation-provider.xml"); providerContext.start();