大家好,我是烤鸭:

使用dubbo的时候,遇到如下的问题。
    Serialized class com.xxx.xxxService must implement java.io.Serializable

1.  异常

dubbo无论使用哪个协议传递参数的时候,都需要参数实现序列化接口。
所以提示这个很大原因在于传递的参数没有实现序列化,但是一般都提示参数,为什么提示service 没有实现序列化。
以下是我使用test方法时的异常信息。

com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method updateObuStatus in the service com.etc.service.car.RpcEtcCarInfoService. Tried 3 times of the providers [168.1.1.68:20888] (1/1) from the registry 168.1.1.26:2181 on the consumer 192.168.191.1 using the dubbo version 2.6.2. Last error is: Failed to invoke remote method: updateObuStatus, provider: dubbo://168.1.1.68:20888/com.etc.service.car.RpcEtcCarInfoService?anyhost=true&application=etc-highway-card&check=false&default.timeout=600000&dubbo=2.6.2&generic=false&interface=com.etc.service.car.RpcEtcCarInfoService&methods=updateCarStatus,queryCustomerInfoByCar,zolCreditQuery,updateObuStatus&pid=61936&register.ip=192.168.191.1&remote.timestamp=1572940684076&revision=2.2.0&side=consumer&timeout=60000&timestamp=1572998190117, cause: Failed to send message Request [id=2, version=2.0.0, twoway=true, event=false, broken=false, data=RpcInvocation [methodName=updateObuStatus, parameterTypes=[class com.etc.dto.UpdateObuStatusRequest], arguments=[UpdateObuStatusRequest(carNum=111, vehicleNo=null, vehicleColor=null, tenantId=null, obuActiveTime=null, obuActiveNo=1111, remark=null)], attachments={path=com.etc.service.car.RpcEtcCarInfoService, interface=com.etc.service.car.RpcEtcCarInfoService, version=0.0.0, timeout=60000}]] to /168.1.1.68:20888, cause: Serialized class com.etc.highway.CreditLogServiceTest must implement java.io.SerializableJava field: final com.etc.highway.CreditLogServiceTest com.etc.highway.CreditLogServiceTest$1.this$0at com.alibaba.dubbo.rpc.cluster.support.FailoverClusterInvoker.doInvoke(FailoverClusterInvoker.java:102)at com.alibaba.dubbo.rpc.cluster.support.AbstractClusterInvoker.invoke(AbstractClusterInvoker.java:238)at com.alibaba.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker.invoke(MockClusterInvoker.java:75)at com.alibaba.dubbo.rpc.proxy.InvokerInvocationHandler.invoke(InvokerInvocationHandler.java:52)at com.alibaba.dubbo.common.bytecode.proxy13.updateObuStatus(proxy13.java)at com.etc.highway.CreditLogServiceTest.getOfflineDataList(CreditLogServiceTest.java:41)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:73)at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:83)at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)at org.junit.runners.ParentRunner.run(ParentRunner.java:363)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)at org.junit.runner.JUnitCore.run(JUnitCore.java:137)at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: com.alibaba.dubbo.remoting.RemotingException: Failed to send message Request [id=2, version=2.0.0, twoway=true, event=false, broken=false, data=RpcInvocation [methodName=updateObuStatus, parameterTypes=[class com.etc.dto.UpdateObuStatusRequest], arguments=[UpdateObuStatusRequest(carNum=111, vehicleNo=null, vehicleColor=null, tenantId=null, obuActiveTime=null, obuActiveNo=1111, remark=null)], attachments={path=com.etc.service.car.RpcEtcCarInfoService, interface=com.etc.service.car.RpcEtcCarInfoService, version=0.0.0, timeout=60000}]] to /168.1.1.68:20888, cause: Serialized class com.etc.highway.CreditLogServiceTest must implement java.io.SerializableJava field: final com.etc.highway.CreditLogServiceTest com.etc.highway.CreditLogServiceTest$1.this$0at com.alibaba.dubbo.remoting.transport.netty.NettyChannel.send(NettyChannel.java:110)at com.alibaba.dubbo.remoting.transport.AbstractClient.send(AbstractClient.java:265)at com.alibaba.dubbo.remoting.transport.AbstractPeer.send(AbstractPeer.java:53)at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeChannel.request(HeaderExchangeChannel.java:115)at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeClient.request(HeaderExchangeClient.java:90)at com.alibaba.dubbo.rpc.protocol.dubbo.ReferenceCountExchangeClient.request(ReferenceCountExchangeClient.java:83)at com.alibaba.dubbo.rpc.protocol.dubbo.DubboInvoker.doInvoke(DubboInvoker.java:95)at com.alibaba.dubbo.rpc.protocol.AbstractInvoker.invoke(AbstractInvoker.java:148)at com.alibaba.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:75)at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:72)at com.alibaba.dubbo.rpc.protocol.dubbo.filter.FutureFilter.invoke(FutureFilter.java:54)at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:72)at com.alibaba.dubbo.rpc.filter.ConsumerContextFilter.invoke(ConsumerContextFilter.java:48)at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:72)at com.alibaba.dubbo.rpc.listener.ListenerInvokerWrapper.invoke(ListenerInvokerWrapper.java:77)at com.alibaba.dubbo.rpc.protocol.InvokerWrapper.invoke(InvokerWrapper.java:56)at com.alibaba.dubbo.rpc.cluster.support.FailoverClusterInvoker.doInvoke(FailoverClusterInvoker.java:78)... 35 more
Caused by: java.lang.RuntimeException: Serialized class com.etc.highway.CreditLogServiceTest must implement java.io.SerializableJava field: final com.etc.highway.CreditLogServiceTest com.etc.highway.CreditLogServiceTest$1.this$0at com.alibaba.com.caucho.hessian.io.JavaSerializer$FieldSerializer.serialize(JavaSerializer.java:300)at com.alibaba.com.caucho.hessian.io.JavaSerializer.writeInstance(JavaSerializer.java:280)at com.alibaba.com.caucho.hessian.io.JavaSerializer.writeObject(JavaSerializer.java:247)at com.alibaba.com.caucho.hessian.io.Hessian2Output.writeObject(Hessian2Output.java:391)at com.alibaba.dubbo.common.serialize.hessian2.Hessian2ObjectOutput.writeObject(Hessian2ObjectOutput.java:88)at com.alibaba.dubbo.rpc.protocol.dubbo.DubboCodec.encodeRequestData(DubboCodec.java:176)at com.alibaba.dubbo.remoting.exchange.codec.ExchangeCodec.encodeRequest(ExchangeCodec.java:234)at com.alibaba.dubbo.remoting.exchange.codec.ExchangeCodec.encode(ExchangeCodec.java:71)at com.alibaba.dubbo.rpc.protocol.dubbo.DubboCountCodec.encode(DubboCountCodec.java:38)at com.alibaba.dubbo.remoting.transport.netty.NettyCodecAdapter$InternalEncoder.encode(NettyCodecAdapter.java:80)at org.jboss.netty.handler.codec.oneone.OneToOneEncoder.handleDownstream(OneToOneEncoder.java:66)at com.alibaba.dubbo.remoting.transport.netty.NettyHandler.writeRequested(NettyHandler.java:98)at org.jboss.netty.channel.Channels.write(Channels.java:611)at org.jboss.netty.channel.Channels.write(Channels.java:578)at org.jboss.netty.channel.AbstractChannel.write(AbstractChannel.java:251)at com.alibaba.dubbo.remoting.transport.netty.NettyChannel.send(NettyChannel.java:100)... 51 more
Caused by: java.lang.IllegalStateException: Serialized class com.etc.highway.CreditLogServiceTest must implement java.io.Serializableat com.alibaba.com.caucho.hessian.io.SerializerFactory.getDefaultSerializer(SerializerFactory.java:395)at com.alibaba.com.caucho.hessian.io.SerializerFactory.getSerializer(SerializerFactory.java:369)at com.alibaba.com.caucho.hessian.io.Hessian2Output.writeObject(Hessian2Output.java:389)at com.alibaba.com.caucho.hessian.io.JavaSerializer$FieldSerializer.serialize(JavaSerializer.java:298)... 66 more

2.  分析

极大的可能在于service用了rpc中的request对象构建了匿名内部类
所以提示  Java field: final xxx.this$0
JDK8 以后,匿名内部类默认用 final 修饰。
这个 UpdateObuStatusRequest 是本来rpc-api的jar中的需要传参数的对象,错误代码如下,但是在调用的时候,使用了匿名内部类。

    @Autowiredprivate RpcEtcCarInfoService rpcEtcCarInfoService;@Testpublic void test() throws InterruptedException {// 2.通知teacherUpdateObuStatusRequest updateObuStatusRequest = new UpdateObuStatusRequest() {{this.setCarNum("111");this.setObuActiveNo("1111");}};ExterResponse exterResponse = rpcEtcCarInfoService.updateObuStatus(updateObuStatusRequest);System.out.println(JSON.toJSONString(exterResponse));}

跟了下源码,可以看到的是。在使用netty进行 消息发送的时候,对参数进行序列化,用反射获取的是匿名内部类的对应的当前类的对象。刚调用 send 方法的时候,看到的request 对象的参数是对的。

进行序列化的时候。发现这个object是当前测试类的对象。

好吧,下次注意。另外不建议匿名内部类的写法

由于创建的对象用final 修饰后,直接进入了常量池,生存时间不再和调用方法是一样的,容易造成 leak memory(内存泄露)。

Serialized class com.xxx.xxxService must implement java.io.Serializable相关推荐

  1. Dubbo Serialized class xxx.Xxx must implement java.io.Serializable问题解决

    问题描述: Caused by: java.lang.IllegalStateException: Serialized class com.user.UserDto must implement j ...

  2. 错误记录——Serialized class com.cql.entity.Teacher must implement java.io.Serializable

    在使用dubbo的时候,出现Serialized class com.*.xxx must implement java.io.Serializable,的一个错误 原因:实体类未进行序列化,在对应的 ...

  3. dubbo 报错Serialized class com.spring.boot.entity.User must implement java.io.Serializable

    这个报错是说dubbo在传输数据的时候反序列化报错, 使用dubbo进行数据传递时,需让作为消息传递的类序列化. 2019-03-26 16:45:01.228 ERROR 14968 --- [ni ...

  4. 解决Serialized class ** must implement java.io.Serializable问题

    在使用dubbo进行传递实体类时,会报错需要实现序列化问题 只需在自己的model实体类里面implements Serializable即可解决,如下 package com.pang.back.M ...

  5. java对象序列化java.io.Serializable 接口实践

    java.io.Serializable 接口没有任何方法和字段,仅仅表示实现它的类的对象可以被序列化.实现了这个接口的所有类及其子类都可以对象序列化. 序列化前,虚拟机要清楚每个对象的结构,所以序列 ...

  6. java.io.Serializable 序列化问题【原】

    java.io.Serializable 序列化问题 Person.java package a.b.c;public class Person implements java.io.Serializ ...

  7. Kotlin 编译报 Cannot access ‘java.io.Serializable‘ which is a supertype of ‘kotlin.String‘.

    完整build错误:Cannot access 'java.io.Serializable' which is a supertype of 'kotlin.String'. Check your m ...

  8. (已解决)ubuntu20.04 jar xvf XXX.zip报错-java.io.EOFException:Unexpected end of ZLIB input stream

    报错截图 如下 我在服务器上解压缩defects4j-repos.zip,但是出现了如上错误.通过SFTP我把这个压缩包传到了本地win10上面,进行解压缩.本地解压缩软件(有图形界面的好处显现了)告 ...

  9. java.io.serializable_java.io.NotSerializableException即使我实现“Serializable”

    我有一点问题: 我想测试 android上的序列化(使用eclipse),并找到了一个如何做的例子. 我知道我需要在我要序列化的类中实现"Serializable",我已经这样做并 ...

最新文章

  1. 解决transition动画与display冲突的几种方法
  2. Cocoapods安装过程【转载】
  3. Python Cookbook (2) 文件
  4. Python 序列与映射的解包操作
  5. 实例31:python
  6. 循环斐波那契数列_第五课:斐波那契数列(第一课时)
  7. 文本解析 python 多行,关于python:基于文本的数据格式,支持多行字符串
  8. python 5的倍数_查找所有低于1000的数字的和,这是Python中3或5的倍数
  9. 不错!SpringBoot发布Jar包优化瘦身指南!
  10. PCL学习(4)——octree
  11. 基于知识图谱的推荐系统综述
  12. Java虚拟机(一)——内存管理
  13. “开发者的面试完全是无稽之谈”
  14. 用 js判断 一个数是否是素数(质数)_小学数学知识点1~6年级汇总整理,收藏起来随时用!(下)...
  15. 【GDB调试学习笔记】利用core文件调试程序
  16. 使用maven搭建ssm项目配置+tomact
  17. PRISM概率模型检测器初使用--骰子模型
  18. Mac教程——怎么升级系统版本
  19. python实现千牛客服自动回复语_千牛会用到的回复语有哪些?千牛自动回复短语大全...
  20. 西安的草根互联网要靠外力挽救吗?

热门文章

  1. 01:面试的正确姿势你掌握了吗?
  2. Word转PDF出现空白页解决办法(以Word2016为例)
  3. 《大五人格心理学》读书笔记
  4. 关于layout_alignParentLeft、layout_alignLeft、layout_toLeftOf、layout_marginLeft的区别
  5. 中国计量大学调剂计算机技术,2018年中国计量大学考研调剂程序
  6. 49_ue4进阶末日生存游戏开发[布娃娃系统实现死亡倒地]
  7. 计算机有点坏了英语怎么说,“电脑坏了”用英语怎么说?千万别用“the computer break”!...
  8. android 返回键 键盘,关于Android返回键关闭键盘和返回问题...求大神ING~
  9. vue 实现上拉加载下拉刷新(思路清晰)
  10. linux写一个命令用echo输出,echo命令的15个用法