apache / dubbo

The java implementation of Apache Dubbo. An RPC and microservice framework.
https://dubbo.apache.org/
Apache License 2.0
40.51k stars 26.43k forks source link

@Reference注解使用mock="return null"属性报错 #2689

Closed a601942905git closed 6 years ago

a601942905git commented 6 years ago

在测试本地伪装的时候,在@Reference注解中使用mock="return null"属性会出现ClassNotFoundException异常,而在xml配置文件中使用mock="return null"就没有问题,难道注解不支持嘛?

diecui1202 commented 6 years ago

@mercyblitz could u take some time to check this issue?

a601942905git commented 6 years ago

I can provide the code for you mock-test

a601942905git commented 6 years ago

@diecui1202 no one to check this issue?

beiwei30 commented 6 years ago

@a601942905git I'm on it.

beiwei30 commented 6 years ago

@a601942905git I tried to verify it on 2.6.5-SNAPSHOT, it works as expected.

See below for what I changed:

boot-dubbo-consumer/pom.xml

diff --git a/boot-dubbo-consumer/pom.xml b/boot-dubbo-consumer/pom.xml
index 8eacf77..fab9eec 100644
--- a/boot-dubbo-consumer/pom.xml
+++ b/boot-dubbo-consumer/pom.xml
@@ -28,9 +28,27 @@
             <version>0.0.1-SNAPSHOT</version>
         </dependency>

+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>dubbo</artifactId>
+            <version>2.6.5-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.alibaba.spring</groupId>
+            <artifactId>spring-context-support</artifactId>
+            <version>1.0.2</version>
+        </dependency>
+
         <dependency>
             <groupId>com.alibaba.boot</groupId>
             <artifactId>dubbo-spring-boot-starter</artifactId>
+            <exclusions>
+                <exclusion>
+                    <groupId>com.alibaba</groupId>
+                    <artifactId>dubbo</artifactId>
+                </exclusion>
+            </exclusions>
         </dependency>

         <dependency>

com/boot/dubbo/mock/FooCustomerService.java

diff --git a/boot-dubbo-consumer/src/main/java/com/boot/dubbo/mock/FooCustomerService.java b/boot-dubbo-consumer/src/main/java/com/boot/dubbo/mock/FooCustomerService.java
index dc6c2a1..300e7e5 100644
--- a/boot-dubbo-consumer/src/main/java/com/boot/dubbo/mock/FooCustomerService.java
+++ b/boot-dubbo-consumer/src/main/java/com/boot/dubbo/mock/FooCustomerService.java
@@ -12,7 +12,8 @@ import org.springframework.stereotype.Service;
 @Service
 public class FooCustomerService {

-    @Reference(mock = "com.boot.dubbo.mock.MockService")
+//    @Reference(mock = "com.boot.dubbo.mock.MockService")
+    @Reference(mock = "return hello")
     private FooService fooService;

     public String testMock() {

output:

Caused by: com.alibaba.dubbo.remoting.TimeoutException: Waiting server-side response timeout. start time: 2018-10-31 16:37:11.130, end time: 2018-10-31 16:37:14.131, client elapsed: 0 ms, server elapsed: 3001 ms, timeout: 3000 ms, request: Request [id=2, version=2.0.2, twoway=true, event=false, broken=false, data=RpcInvocation [methodName=testFoo, parameterTypes=[], arguments=[], attachments={path=com.boot.dubbo.mock.FooService, interface=com.boot.dubbo.mock.FooService, version=0.0.0, timeout=3000}]], channel: /169.254.14.63:56601 -> /169.254.14.63:20880
    at com.alibaba.dubbo.remoting.exchange.support.DefaultFuture.get(DefaultFuture.java:159) ~[dubbo-2.6.5-SNAPSHOT.jar:2.6.5-SNAPSHOT]
    at com.alibaba.dubbo.remoting.exchange.support.DefaultFuture.get(DefaultFuture.java:135) ~[dubbo-2.6.5-SNAPSHOT.jar:2.6.5-SNAPSHOT]
    at com.alibaba.dubbo.rpc.protocol.dubbo.DubboInvoker.doInvoke(DubboInvoker.java:95) ~[dubbo-2.6.5-SNAPSHOT.jar:2.6.5-SNAPSHOT]
    at com.alibaba.dubbo.rpc.protocol.AbstractInvoker.invoke(AbstractInvoker.java:155) ~[dubbo-2.6.5-SNAPSHOT.jar:2.6.5-SNAPSHOT]
    at com.alibaba.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:75) ~[dubbo-2.6.5-SNAPSHOT.jar:2.6.5-SNAPSHOT]
    at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:72) ~[dubbo-2.6.5-SNAPSHOT.jar:2.6.5-SNAPSHOT]
    at com.alibaba.dubbo.rpc.protocol.dubbo.filter.FutureFilter.invoke(FutureFilter.java:54) ~[dubbo-2.6.5-SNAPSHOT.jar:2.6.5-SNAPSHOT]
    at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:72) ~[dubbo-2.6.5-SNAPSHOT.jar:2.6.5-SNAPSHOT]
    at com.alibaba.dubbo.rpc.filter.ConsumerContextFilter.invoke(ConsumerContextFilter.java:49) ~[dubbo-2.6.5-SNAPSHOT.jar:2.6.5-SNAPSHOT]
    at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:72) ~[dubbo-2.6.5-SNAPSHOT.jar:2.6.5-SNAPSHOT]
    at com.alibaba.dubbo.rpc.listener.ListenerInvokerWrapper.invoke(ListenerInvokerWrapper.java:77) ~[dubbo-2.6.5-SNAPSHOT.jar:2.6.5-SNAPSHOT]
    at com.alibaba.dubbo.rpc.protocol.InvokerWrapper.invoke(InvokerWrapper.java:56) ~[dubbo-2.6.5-SNAPSHOT.jar:2.6.5-SNAPSHOT]
    at com.alibaba.dubbo.rpc.cluster.support.FailoverClusterInvoker.doInvoke(FailoverClusterInvoker.java:78) ~[dubbo-2.6.5-SNAPSHOT.jar:2.6.5-SNAPSHOT]
    ... 12 common frames omitted

调用服务返回结果:hello
beiwei30 commented 6 years ago

ps, your samples looks good. Are you interested in building https://github.com/dubbo/dubbo-samples together, to show all Dubbo's features as many as possible, and as simple as possible?