From 86c473771adb859a361d369248b809c245898bf8 Mon Sep 17 00:00:00 2001 From: Ian Luo Date: Thu, 8 Nov 2018 14:47:16 +0800 Subject: [PATCH] merge pull request #2353 to 2.6.x to fix #2353 (#2761) --- .../ServiceAnnotationBeanPostProcessor.java | 5 +++-- .../dubbo/config/spring/ConfigTest.java | 20 ++++++++++++++++++- .../annotation/provider/HelloServiceImpl.java | 2 +- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/dubbo-config/dubbo-config-spring/src/main/java/com/alibaba/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationBeanPostProcessor.java b/dubbo-config/dubbo-config-spring/src/main/java/com/alibaba/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationBeanPostProcessor.java index 9ba4cc567cc..d34b4a60e7f 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/com/alibaba/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationBeanPostProcessor.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/com/alibaba/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationBeanPostProcessor.java @@ -369,7 +369,8 @@ 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)); @@ -483,4 +484,4 @@ public void setBeanClassLoader(ClassLoader classLoader) { this.classLoader = classLoader; } -} \ No newline at end of file +} diff --git a/dubbo-config/dubbo-config-spring/src/test/java/com/alibaba/dubbo/config/spring/ConfigTest.java b/dubbo-config/dubbo-config-spring/src/test/java/com/alibaba/dubbo/config/spring/ConfigTest.java index 69f716b25cc..edaaa88a3bb 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/com/alibaba/dubbo/config/spring/ConfigTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/com/alibaba/dubbo/config/spring/ConfigTest.java @@ -33,6 +33,7 @@ import com.alibaba.dubbo.config.spring.annotation.consumer.AnnotationAction; import com.alibaba.dubbo.config.spring.api.DemoService; import com.alibaba.dubbo.config.spring.api.HelloService; +import com.alibaba.dubbo.config.spring.context.annotation.provider.ProviderConfiguration; import com.alibaba.dubbo.config.spring.filter.MockFilter; import com.alibaba.dubbo.config.spring.impl.DemoServiceImpl; import com.alibaba.dubbo.config.spring.impl.HelloServiceImpl; @@ -51,6 +52,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; @@ -106,6 +108,22 @@ public void testServiceClass() { } } + @Test + public void testServiceAnnotation() { + 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 @SuppressWarnings("unchecked") public void testProviderNestedService() { @@ -999,4 +1017,4 @@ public void testGenericServiceConfigThroughSpring() throws Exception { ctx.destroy(); } } -} \ No newline at end of file +} diff --git a/dubbo-config/dubbo-config-spring/src/test/java/com/alibaba/dubbo/config/spring/context/annotation/provider/HelloServiceImpl.java b/dubbo-config/dubbo-config-spring/src/test/java/com/alibaba/dubbo/config/spring/context/annotation/provider/HelloServiceImpl.java index 9d0fdbb19b9..a9212f0ddc4 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/com/alibaba/dubbo/config/spring/context/annotation/provider/HelloServiceImpl.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/com/alibaba/dubbo/config/spring/context/annotation/provider/HelloServiceImpl.java @@ -24,7 +24,7 @@ * * @since 2.5.9 */ -@Service +@Service(interfaceName = "com.alibaba.dubbo.config.spring.api.HelloService") public class HelloServiceImpl implements HelloService { @Override