文章目录
- 引言
- 问题重现
- 解决方案
- 全部报错
引言
在写springboot+dubbo+zookeeper搭建的微服务架构项目时,出现了该错误。该错误确实以前也没有遇见过,因为这是我第一次去编写微服务项目,遇见该错误后,我首先是自己排查了一遍,发现就在两个接口中有该错误,但是我又找不出来是什么错误,于是就去搜索相关资料。在搜索资料的时候发现在CSDN没有我的问题的相关资料,最终是在其它途径中搜索得到答案:不建议wrapper 在 dubbo 中来回传输,QueryWrapper无法解析
当前版本:
dubbo-spring-boot-starter
版本号:2.7.3
mybatis-plus-boot-starter
版本号:3.5.1
在controller中使用mybatis-plus的wrapper去查询数据时出现错误,主要报错如下(如想看见全部报错请点击目录超链接)
错误一:
2022-08-08 18:12:13,675 WARN [org.apache.dubbo.remoting.exchange.codec.ExchangeCodec] -[DUBBO] Skip input stream 163, dubbo version: 2.7.3, current host: 192.168.1.32022-08-08 18:12:13,696 WARN [org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation] -[DUBBO] Decode argument failed: com.baomidou.mybatisplus.core.conditions.segments.MergeSegments.normal: java.util.ArrayList ([]) cannot be assigned to 'com.baomidou.mybatisplus.core.conditions.segments.NormalSegmentList', dubbo version: 2.7.3, current host: 192.168.1.3com.alibaba.com.caucho.hessian.io.HessianFieldException: com.baomidou.mybatisplus.core.conditions.segments.MergeSegments.normal: java.util.ArrayList ([]) cannot be assigned to 'com.baomidou.mybatisplus.core.conditions.segments.NormalSegmentList'
错误二:
Caused by: java.lang.IllegalArgumentException: Can not set final com.baomidou.mybatisplus.core.conditions.segments.NormalSegmentList field com.baomidou.mybatisplus.core.conditions.segments.MergeSegments.normal to null valueat sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)at sun.reflect.UnsafeQualifiedObjectFieldAccessorImpl.set(UnsafeQualifiedObjectFieldAccessorImpl.java:83)at java.lang.reflect.Field.set(Field.java:764)at com.alibaba.com.caucho.hessian.io.JavaDeserializer$ObjectFieldDeserializer.deserialize(JavaDeserializer.java:408)... 42 more2022-08-08 18:12:13,696 WARN [org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation] -[DUBBO] Decode rpc invocation failed: expected map/object at java.lang.Boolean (true), dubbo version: 2.7.3, current host: 192.168.1.3com.alibaba.com.caucho.hessian.io.HessianProtocolException: expected map/object at java.lang.Boolean (true)
问题重现
在以dubbo和zookeeper搭建的微服务架构中的Consumer的Controller中执行以下方法就会报错
@ApiOperation(value = "后台分页条件查询标签列表")@GetMapping("/listTags")public Result listTags(@RequestParam(value = "current",required = true,defaultValue = "1") Integer current, @RequestParam(value = "size",required = true,defaultValue = "5")Integer size, @RequestParam(value = "tagName",required = false) String tagName){Page<Tag> page = new Page<>(current, size);QueryWrapper<Tag> wrapper = new QueryWrapper<>();if(tagName != null && tagName != ""){wrapper.like("tag_name", tagName);}Page<Tag> tagPage = tagService.page(page, wrapper);long total = tagPage.getTotal();List<Tag> data = tagPage.getRecords();if(total>0){returnResult.ok().data("data", data).data("total", total);}else {returnResult.ok().setMessage("没有相关数据");}}
解决方案
不建议wrapper 在 dubbo 中来回传输,对外暴露的是查询参数或者对象,QueryWrapper无法解析。
所以,我们只需要将Controller内实现的功能转移到服务提供者(ServiceImpl)去实现即可,那么我们就可以不用在dubbo中去传递wrapper
全部报错
这里展示我全部的报错,该报错内容重复输出了三次
2022-08-08 18:12:13,696 WARN [org.apache.dubbo.remoting.exchange.codec.ExchangeCodec] -[DUBBO] Skip input stream 163, dubbo version: 2.7.3, current host: 192.168.1.32022-08-08 18:12:13,698 WARN [org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation] -[DUBBO] Decode argument failed: com.baomidou.mybatisplus.core.conditions.segments.MergeSegments.normal: java.util.ArrayList ([]) cannot be assigned to 'com.baomidou.mybatisplus.core.conditions.segments.NormalSegmentList', dubbo version: 2.7.3, current host: 192.168.1.3com.alibaba.com.caucho.hessian.io.HessianFieldException: com.baomidou.mybatisplus.core.conditions.segments.MergeSegments.normal: java.util.ArrayList ([]) cannot be assigned to 'com.baomidou.mybatisplus.core.conditions.segments.NormalSegmentList'at com.alibaba.com.caucho.hessian.io.JavaDeserializer.logDeserializeError(JavaDeserializer.java:171)at com.alibaba.com.caucho.hessian.io.JavaDeserializer$ObjectFieldDeserializer.deserialize(JavaDeserializer.java:410)at com.alibaba.com.caucho.hessian.io.JavaDeserializer.readObject(JavaDeserializer.java:276)at com.alibaba.com.caucho.hessian.io.JavaDeserializer.readObject(JavaDeserializer.java:203)at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObjectInstance(Hessian2Input.java:2818)at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:2145)at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:2074)at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:2118)at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:2074)at com.alibaba.com.caucho.hessian.io.JavaDeserializer$ObjectFieldDeserializer.deserialize(JavaDeserializer.java:406)at com.alibaba.com.caucho.hessian.io.JavaDeserializer.readObject(JavaDeserializer.java:276)at com.alibaba.com.caucho.hessian.io.JavaDeserializer.readObject(JavaDeserializer.java:203)at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObjectInstance(Hessian2Input.java:2818)at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:2145)at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:2074)at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:2118)at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:2074)at org.apache.dubbo.common.serialize.hessian2.Hessian2ObjectInput.readObject(Hessian2ObjectInput.java:92)at org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation.decode(DecodeableRpcInvocation.java:116)at org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation.decode(DecodeableRpcInvocation.java:73)at org.apache.dubbo.rpc.protocol.dubbo.DubboCodec.decodeBody(DubboCodec.java:132)at org.apache.dubbo.remoting.exchange.codec.ExchangeCodec.decode(ExchangeCodec.java:122)at org.apache.dubbo.remoting.exchange.codec.ExchangeCodec.decode(ExchangeCodec.java:82)at org.apache.dubbo.rpc.protocol.dubbo.DubboCountCodec.decode(DubboCountCodec.java:48)at org.apache.dubbo.remoting.transport.netty4.NettyCodecAdapter$InternalDecoder.decode(NettyCodecAdapter.java:90)at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:507)at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:446)at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:276)at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719)at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)at java.lang.Thread.run(Thread.java:748)Caused by: java.lang.IllegalArgumentException: Can not set final com.baomidou.mybatisplus.core.conditions.segments.NormalSegmentList field com.baomidou.mybatisplus.core.conditions.segments.MergeSegments.normal to null valueat sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)at sun.reflect.UnsafeQualifiedObjectFieldAccessorImpl.set(UnsafeQualifiedObjectFieldAccessorImpl.java:83)at java.lang.reflect.Field.set(Field.java:764)at com.alibaba.com.caucho.hessian.io.JavaDeserializer$ObjectFieldDeserializer.deserialize(JavaDeserializer.java:408)... 42 more2022-08-08 18:12:13,699 WARN [org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation] -[DUBBO] Decode rpc invocation failed: expected map/object at java.lang.Boolean (true), dubbo version: 2.7.3, current host: 192.168.1.3com.alibaba.com.caucho.hessian.io.HessianProtocolException: expected map/object at java.lang.Boolean (true)at com.alibaba.com.caucho.hessian.io.AbstractDeserializer.error(AbstractDeserializer.java:131)at com.alibaba.com.caucho.hessian.io.AbstractMapDeserializer.readObject(AbstractMapDeserializer.java:70)at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:2267)at com.alibaba.com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:2074)at org.apache.dubbo.common.serialize.hessian2.Hessian2ObjectInput.readObject(Hessian2ObjectInput.java:92)at org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation.decode(DecodeableRpcInvocation.java:126)at org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation.decode(DecodeableRpcInvocation.java:73)at org.apache.dubbo.rpc.protocol.dubbo.DubboCodec.decodeBody(DubboCodec.java:132)at org.apache.dubbo.remoting.exchange.codec.ExchangeCodec.decode(ExchangeCodec.java:122)at org.apache.dubbo.remoting.exchange.codec.ExchangeCodec.decode(ExchangeCodec.java:82)at org.apache.dubbo.rpc.protocol.dubbo.DubboCountCodec.decode(DubboCountCodec.java:48)at org.apache.dubbo.remoting.transport.netty4.NettyCodecAdapter$InternalDecoder.decode(NettyCodecAdapter.java:90)at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:507)at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:446)at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:276)at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719)at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)at java.lang.Thread.run(Thread.java:748)