Closed aggible closed 6 years ago
检查下配置文件吧,provider中用dubbo:service/ 定义好接口,ref指向接口的实现类,consumer中用dubbo:reference/,指向接口。贴出你的配置来看看吧
我没有用任何配置文件,我是API配置,以上代码就是我项目里和dubbo相关的全部,参考的是 http://dubbo.io/User+Guide.htm#UserGuide-APIConfig
我现在换上Spring并使用XML配置的方式了
provider端:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="center" />
<dubbo:registry address="redis://192.168.1.11:6379" />
<dubbo:protocol name="dubbo" port="20880" />
<!-- 声明需要暴露的服务接口 -->
<dubbo:service interface="soa.service.PlayerService" ref="playerService" />
<bean id="playerService" class="soa.service.PlayerServiceImpl" />
</beans>
consumer端:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<!-- consumer application name -->
<dubbo:application name="consumer-of-helloworld-app" />
<!-- registry address, used for consumer to discover services -->
<dubbo:registry address="redis://192.168.1.11:6379" />
<!-- which service to consume? -->
<dubbo:reference id="PlayerService" interface="soa.service.PlayerService" />
</beans>
JAVA类没有变。PlayerService和PlayerServiceImpl在Provider端,PlayerService在Consumer端
还是一样的问题,在Consumer端调用后,Provider端会出一个错误。
Caused by: java.lang.ClassCastException: soa.service.PlayerServiceImpl cannot be cast to soa.service.PlayerServiceImpl
错误堆栈和顶楼完全相同
建议把所有项目代码上传到自己的git仓库,也好帮你看看是不是代码有问题。
有没有自定义类加载之类的?
建议增加jvm
参数-verbose:class
,把类加载过程打印出来,看看是不是加载了两份存根类。
楼主这个问题解决了么
我也遇到了相同的错误,求问这个问题怎么解决的?
我也遇到了同样问题,但我的环境是在 spring boot 下,报告的异常类似,都是说cast exception,不能把 abc.class cast 为 abc.class。后来添加 jvm 参数 -verbose:class,发现的确是把 abc.class 加载了两次,猜测是因为 spring-boot 开发工具“spring-boot-devtools”导致的,因为这个工具会监控文件更改并自动重新装载类。去掉 spring-boot-devtools 后,问题解决。也许大家的根源不一样,但估计都是“重新装载类”这种功能导致的,供大家参考。
我也遇到这个问题了, 是spring-boot-devtools 导致的, 猜测是重新加载类, verbose:class 看到也是加载了一个类, 过程中类也没有修改, 再看看dev 的热布署机制
me 2,spring-boot-devtools java.lang.IllegalArgumentException: java.lang.ClassCastException ,有解决办法吗?除了去掉spring-boot-devtools
我也遇到这个问题了,` Exception in thread "main" com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method findClearingById in the service c.h.p.clearing.service.ClearingService. Tried 3 times of the providers [169.254.126.234:20881] (1/1) from the registry 127.0.0.1:2181 on the consumer 169.254.126.234 using the dubbo version 2.8.4. Last error is: Failed to invoke remote method: findClearingById, provider: dubbo://169.254.126.234:20881/c.h.p.clearing.service.ClearingService?anyhost=true&application=consumer&check=false&dubbo=2.8.4&generic=false&interface=c.h.p.clearing.service.ClearingService&methods=updateClearingBillName,addClearingBillItem,addClearingBill,completeClearing,findClearingBillPage,findClearingById,findClearingBillItemPage,deleteClearingBillItemById&pid=35568&revision=1.0&side=consumer×tamp=1485133339215&version=1.0, cause: com.alibaba.dubbo.rpc.RpcException: Failed to invoke remote proxy method findClearingById to registry://127.0.0.1:2181/com.alibaba.dubbo.registry.RegistryService?application=provider&dubbo=2.8.4&export=dubbo%3A%2F%2F169.254.126.234%3A20881%2Fc.h.p.clearing.service.ClearingService%3Fanyhost%3Dtrue%26application%3Dprovider%26dubbo%3D2.8.4%26generic%3Dfalse%26interface%3Dc.h.p.clearing.service.ClearingService%26methods%3DupdateClearingBillName%2CaddClearingBillItem%2CaddClearingBill%2CcompleteClearing%2CfindClearingBillPage%2CfindClearingById%2CfindClearingBillItemPage%2CdeleteClearingBillItemById%26pid%3D37920%26revision%3D1.0%26side%3Dprovider%26timestamp%3D1485133301019%26version%3D1.0&pid=37920®istry=zookeeper×tamp=1485133300997, cause: java.lang.ClassCastException: com.sun.proxy.$Proxy70 cannot be cast to c.h.p.clearing.service.ClearingService com.alibaba.dubbo.rpc.RpcException: Failed to invoke remote proxy method findClearingById to registry://127.0.0.1:2181/com.alibaba.dubbo.registry.RegistryService?application=provider&dubbo=2.8.4&export=dubbo%3A%2F%2F169.254.126.234%3A20881%2Fc.h.p.clearing.service.ClearingService%3Fanyhost%3Dtrue%26application%3Dprovider%26dubbo%3D2.8.4%26generic%3Dfalse%26interface%3Dc.h.p.clearing.service.ClearingService%26methods%3DupdateClearingBillName%2CaddClearingBillItem%2CaddClearingBill%2CcompleteClearing%2CfindClearingBillPage%2CfindClearingById%2CfindClearingBillItemPage%2CdeleteClearingBillItemById%26pid%3D37920%26revision%3D1.0%26side%3Dprovider%26timestamp%3D1485133301019%26version%3D1.0&pid=37920®istry=zookeeper×tamp=1485133300997, cause: java.lang.ClassCastException: com.sun.proxy.$Proxy70 cannot be cast to c.h.p.clearing.service.ClearingService 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.monitor.support.MonitorFilter.invoke(MonitorFilter.java:75) 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.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:70) at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91) at com.alibaba.dubbo.rpc.filter.GenericFilter.invoke(GenericFilter.java:132) 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:113) 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: com.sun.proxy.$Proxy70 cannot be cast to c.h.p.clearing.service.ClearingService at com.alibaba.dubbo.common.bytecode.Wrapper0.invokeMethod(Wrapper0.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: com.sun.proxy.$Proxy70 cannot be cast to c.h.p.clearing.service.ClearingService ... 28 more
at com.alibaba.dubbo.rpc.cluster.support.FailoverClusterInvoker.doInvoke(FailoverClusterInvoker.java:101)
at com.alibaba.dubbo.rpc.cluster.support.AbstractClusterInvoker.invoke(AbstractClusterInvoker.java:227)
at com.alibaba.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker.invoke(MockClusterInvoker.java:72)
at com.alibaba.dubbo.rpc.proxy.InvokerInvocationHandler.invoke(InvokerInvocationHandler.java:52)
at com.alibaba.dubbo.common.bytecode.proxy0.findClearingById(proxy0.java)
at c.h.p.springbootdubbo.service.impl.HelloServiceImpl.sayHello(HelloServiceImpl.java:22)
at c.h.p.springbootdubbo.ConsumerApplication.main(ConsumerApplication.java:13)
Caused by: com.alibaba.dubbo.remoting.RemotingException: com.alibaba.dubbo.rpc.RpcException: Failed to invoke remote proxy method findClearingById to registry://127.0.0.1:2181/com.alibaba.dubbo.registry.RegistryService?application=provider&dubbo=2.8.4&export=dubbo%3A%2F%2F169.254.126.234%3A20881%2Fc.h.p.clearing.service.ClearingService%3Fanyhost%3Dtrue%26application%3Dprovider%26dubbo%3D2.8.4%26generic%3Dfalse%26interface%3Dc.h.p.clearing.service.ClearingService%26methods%3DupdateClearingBillName%2CaddClearingBillItem%2CaddClearingBill%2CcompleteClearing%2CfindClearingBillPage%2CfindClearingById%2CfindClearingBillItemPage%2CdeleteClearingBillItemById%26pid%3D37920%26revision%3D1.0%26side%3Dprovider%26timestamp%3D1485133301019%26version%3D1.0&pid=37920®istry=zookeeper×tamp=1485133300997, cause: java.lang.ClassCastException: com.sun.proxy.$Proxy70 cannot be cast to c.h.p.clearing.service.ClearingService com.alibaba.dubbo.rpc.RpcException: Failed to invoke remote proxy method findClearingById to registry://127.0.0.1:2181/com.alibaba.dubbo.registry.RegistryService?application=provider&dubbo=2.8.4&export=dubbo%3A%2F%2F169.254.126.234%3A20881%2Fc.h.p.clearing.service.ClearingService%3Fanyhost%3Dtrue%26application%3Dprovider%26dubbo%3D2.8.4%26generic%3Dfalse%26interface%3Dc.h.p.clearing.service.ClearingService%26methods%3DupdateClearingBillName%2CaddClearingBillItem%2CaddClearingBill%2CcompleteClearing%2CfindClearingBillPage%2CfindClearingById%2CfindClearingBillItemPage%2CdeleteClearingBillItemById%26pid%3D37920%26revision%3D1.0%26side%3Dprovider%26timestamp%3D1485133301019%26version%3D1.0&pid=37920®istry=zookeeper×tamp=1485133300997, cause: java.lang.ClassCastException: com.sun.proxy.$Proxy70 cannot be cast to c.h.p.clearing.service.ClearingService 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.monitor.support.MonitorFilter.invoke(MonitorFilter.java:75) 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.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:70) at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91) at com.alibaba.dubbo.rpc.filter.GenericFilter.invoke(GenericFilter.java:132) 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:113) 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: com.sun.proxy.$Proxy70 cannot be cast to c.h.p.clearing.service.ClearingService at com.alibaba.dubbo.common.bytecode.Wrapper0.invokeMethod(Wrapper0.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: com.sun.proxy.$Proxy70 cannot be cast to c.h.p.clearing.service.ClearingService ... 28 more
at com.alibaba.dubbo.remoting.exchange.support.DefaultFuture.returnFromResponse(DefaultFuture.java:190)
at com.alibaba.dubbo.remoting.exchange.support.DefaultFuture.get(DefaultFuture.java:110)
at com.alibaba.dubbo.remoting.exchange.support.DefaultFuture.get(DefaultFuture.java:84)
at com.alibaba.dubbo.rpc.protocol.dubbo.DubboInvoker.doInvoke(DubboInvoker.java:96)
at com.alibaba.dubbo.rpc.protocol.AbstractInvoker.invoke(AbstractInvoker.java:144)
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.FutureFilter.invoke(FutureFilter.java:53)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
at com.alibaba.dubbo.rpc.filter.ConsumerContextFilter.invoke(ConsumerContextFilter.java:48)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
at com.alibaba.dubbo.rpc.listener.ListenerInvokerWrapper.invoke(ListenerInvokerWrapper.java:74)
at com.alibaba.dubbo.rpc.protocol.InvokerWrapper.invoke(InvokerWrapper.java:53)
at com.alibaba.dubbo.rpc.cluster.support.FailoverClusterInvoker.doInvoke(FailoverClusterInvoker.java:77)
... 6 more`
我这也是用springboot启动的,用了teaey的spring-boot-starter-dubbo,也加了spring-boot-devtools。去掉spring-boot-devtools就可以了
没有使用spring-boot-devtools也出现了这个问题,怎么破?有遇到类似问题的吗?
[2017-08-25 21:30:53.572] [DubboServerHandler-10.28.42.206:20880-thread-47] ERROR rpc.filter.ExceptionFilter - [DUBBO] Got unchecked and undeclared exception which called by 10.28.42.206. service: io.welink.xcourt.foundation.api.CacheService, method: findDeviceValidOrderListBaseInfo, exception: java.lang.AbstractMethodError: io.welink.xcourt.foundation.cache.CacheServiceImpl.findDeviceValidOrderListBaseInfo(Ljava/lang/String;Ljava/util/Map;)[Ljava/lang/Object;, dubbo version: 2.8.4, current host: 127.0.0.1 java.lang.AbstractMethodError: io.welink.xcourt.foundation.cache.CacheServiceImpl.findDeviceValidOrderListBaseInfo(Ljava/lang/String;Ljava/util/Map;)[Ljava/lang/Object; 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) 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:70) at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91) at com.alibaba.dubbo.rpc.filter.GenericFilter.invoke(GenericFilter.java:132) 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:113) 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(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
rebuilld一把
I suggest you can dive into the code, set a breakpoint on the exception line, check the two objects' ClassLoader. And then check your application, why loading the class twice.
Feel free to reopen it. &READY-TO-CLOSE&
我没有用Spring,裸API Config写的
redis已经搭好可用 jedis 2.0包已经引了
provider端:
ServiceInitiator的listen启动正常,日志也表示连接上了redis,并成功注册。
接下来我在本机的另外一个Consumer应用里创建了PlayerService的接口存根,调用方式如文档所述
consumer端:
调用时,provider端爆出了这样的错误:
这个转换错误很诡异啊??