SpringBoot整合Dubbo报错: java.lang.ClassCastException

项目采用的SpringBoot加Dubbo进行构建时当远程调用dubbo服务时报以下错误:

com.alibaba.dubbo.remoting.RemotingException: com.alibaba.dubbo.rpc.RpcException: Failed to invoke remote proxy method chat to registry://127.0.0.1:2181/com.alibaba.dubbo.registry.RegistryService?application=health-user&dubbo=2.5.3&export=dubbo%3A%2F%2F192.168.1.116%3A20803%2Forg.health.facede.chat.api.ChatService%3Fanyhost%3Dtrue%26application%3Dhealth-user%26default.retries%3D0%26default.timeout%3D100000%26dubbo%3D2.5.3%26interface%3Dorg.health.facede.chat.api.ChatService%26methods%3Dchat%26pid%3D7340%26revision%3D1.0.0-SNAPSHOT%26side%3Dprovider%26timestamp%3D1475042396821&pid=7340®istry=zookeeper×tamp=1475042396801, cause: java.lang.ClassCastException: org.health.service.chat.impl.ChatServiceImpl cannot be cast to org.health.service.chat.impl.ChatServiceImpl
com.alibaba.dubbo.rpc.RpcException: Failed to invoke remote proxy method chat to registry://127.0.0.1:2181/com.alibaba.dubbo.registry.RegistryService?application=health-user&dubbo=2.5.3&export=dubbo%3A%2F%2F192.168.1.116%3A20803%2Forg.health.facede.chat.api.ChatService%3Fanyhost%3Dtrue%26application%3Dhealth-user%26default.retries%3D0%26default.timeout%3D100000%26dubbo%3D2.5.3%26interface%3Dorg.health.facede.chat.api.ChatService%26methods%3Dchat%26pid%3D7340%26revision%3D1.0.0-SNAPSHOT%26side%3Dprovider%26timestamp%3D1475042396821&pid=7340®istry=zookeeper×tamp=1475042396801, cause: java.lang.ClassCastException: org.health.service.chat.impl.ChatServiceImpl cannot be cast to org.health.service.chat.impl.ChatServiceImpl
    at com.alibaba.dubbo.rpc.proxy.AbstractProxyInvoker.invoke(AbstractProxyInvoker.java:76)
    at com.alibaba.dubbo.rpc.protocol.InvokerWrapper.invoke(InvokerWrapper.java:53)
    at com.alibaba.dubbo.rpc.filter.ExceptionFilter.invoke(ExceptionFilter.java:64)
    at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
    at com.alibaba.dubbo.rpc.filter.TimeoutFilter.invoke(TimeoutFilter.java:42)
    at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
    at com.alibaba.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:75)
    at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
    at com.alibaba.dubbo.rpc.protocol.dubbo.filter.TraceFilter.invoke(TraceFilter.java:78)
    at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
    at com.alibaba.dubbo.rpc.filter.ContextFilter.invoke(ContextFilter.java:60)
    at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
    at com.alibaba.dubbo.rpc.filter.GenericFilter.invoke(GenericFilter.java:112)
    at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
    at com.alibaba.dubbo.rpc.filter.ClassLoaderFilter.invoke(ClassLoaderFilter.java:38)
    at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
    at com.alibaba.dubbo.rpc.filter.EchoFilter.invoke(EchoFilter.java:38)
    at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
    at com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol$1.reply(DubboProtocol.java:108)
    at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.handleRequest(HeaderExchangeHandler.java:84)
    at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.received(HeaderExchangeHandler.java:170)
    at com.alibaba.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:52)
    at com.alibaba.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:82)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: java.lang.ClassCastException: org.health.service.chat.impl.ChatServiceImpl cannot be cast to org.health.service.chat.impl.ChatServiceImpl
    at com.alibaba.dubbo.common.bytecode.Wrapper1.invokeMethod(Wrapper1.java)
    at com.alibaba.dubbo.rpc.proxy.javassist.JavassistProxyFactory$1.doInvoke(JavassistProxyFactory.java:46)
    at com.alibaba.dubbo.rpc.proxy.AbstractProxyInvoker.invoke(AbstractProxyInvoker.java:72)
    ... 25 more
Caused by: java.lang.ClassCastException: org.health.service.chat.impl.ChatServiceImpl cannot be cast to org.health.service.chat.impl.ChatServiceImpl
    ... 28 more

    at com.alibaba.dubbo.remoting.exchange.support.DefaultFuture.returnFromResponse(DefaultFuture.java:190)

用Dubbo做过几个项目了,从来没有碰到过Caused by: java.lang.ClassCastException这种错误,最后经过反复的测试发现原来是因为依赖了SpringBoot的开发者工具才出现的这一个问题,只要把下面的依赖去掉就解决了这一个问题:

        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-devtoolsartifactId>
            <optional>trueoptional>
        dependency>

你可能感兴趣的:(dubbo,springboot)