Dubbo调用Service后返回null
来源:互联网 发布:地球仪软件 编辑:程序博客网 时间:2024/05/21 17:21
问题
- 使用Dubbo服务调用Service后,返回值是null,在Dao层可以确认结果已经查询出来了。
- 其它的Service服务都没有问题。
- 这个Service服务有这样一个特征:是一个树形结构的类,包含上级节点和所有子节点。
猜想
- 可能是这个上级节点和所有子节点导致返回为null,经测,去除这个两个属性后,返回的是有值的。
- 进一步猜测,可能是因为使用mybatis懒加载导致的,经测,在该Mapper中的关联查询禁用懒加载后,没问题了!。
解决思路
查看MyBatis是否开启懒加载
先看下Mybatis的配置文件:
<configuration> <settings> <setting name="cacheEnabled" value="true" /> <setting name="lazyLoadingEnabled" value="true" /><!-- 启用了懒加载 --> <setting name="multipleResultSetsEnabled" value="true" /> <setting name="useColumnLabel" value="true" /> <setting name="defaultExecutorType" value="REUSE" /> <setting name="defaultStatementTimeout" value="25000" /> <setting name="logImpl" value="SLF4J" /> </settings></configuration>
可以看出,MyBatis已经启用了懒加载。
调用的Service及POJO
// 调用的Servicepublic Area getAreaById(String id) { return areaMapper.selectAreaById(id);}// 返回的Area类public class Area implements Serializable{ // 序列化id private static final long serialVersionUID = 6385830546250681339L; // 该节点的上级节点 private Area parent; // 该节点的下级节点 private List<Area> children; // 其它属性及setter/getter方法略}
调用的Mapper
<resultMap id="areaResultMap" type="com.woyi.mhub.area.domain.Area"> <id column="id" jdbcType="CHAR" property="id" /> <result column="createdate" jdbcType="TIMESTAMP" property="createdate" /> <result column="updatedate" jdbcType="TIMESTAMP" property="updatedate" /> <result column="orders" jdbcType="INTEGER" property="orders" /> <result column="name" jdbcType="VARCHAR" property="name" /> <result column="fullname" jdbcType="VARCHAR" property="fullname" /> <result column="treepath" jdbcType="VARCHAR" property="treepath" /> <result column="parentid" jdbcType="CHAR" property="parentid" /> <result column="level" jdbcType="CHAR" property="level" /> <!-- 关联查出上级区域 --> <association property="parent" column="parentid" select="selectAreaById"></association> <!-- 查询出下级区域 --> <collection property="children" column="id" ofType="com.woyi.mhub.area.domain.Area" javaType="java.util.ArrayList" select="selectChildArea"></collection></resultMap><!-- 根据id查询,同时查询出该区域的上级区域和子区域 --><select id="selectAreaById" resultMap="areaResultMap" parameterType="java.lang.String"> select <include refid="Base_Column_List" /> from sys_area where id = #{id,jdbcType=CHAR}</select>
使用上述代码,则调用Dubbo服务后返回null。
解决
禁用关联查询的懒加载,添加fetchType=”eager”属性即可。
<!-- 关联查出上级区域 --><association property="parent" column="parentid" fetchType="eager" select="selectAreaById"></association><!-- 查询出下级区域 --><collection property="children" column="id" fetchType="eager" ofType="com.woyi.mhub.area.domain.Area" javaType="java.util.ArrayList" select="selectChildArea"></collection>
参考
使用mybatis延迟加载时,因为接口返回的是代理对象,导致dubbo序列化后属性值全部为null
mybatis延迟加载导致dubbo值为null解决办法
阅读全文
0 0
- Dubbo调用Service后返回null
- 花擦节 dubbo异步调用变同步,解决异步调用返回值null的问题
- 调用后返回
- dubbo组成原理-service服务调用
- Dubbo系列(三)Dubbo之service实际调用注意事项
- 第二次调用LocalActivityManager startActivity返回null解决方案
- OpenCV中调用cvCreateFileCapture函数返回NULL
- 调用系统相机 data返回null
- 调用 BitmapFactory.decodeByteArray 函数返回 null 值
- springMVC dubbo注解无效,service层返回空指针
- springMVC dubbo注解无效,service层返回空指针
- 为什么在mysql_query()返回成功后,mysql_store_result()有时返回NULL?
- java中SSM整合shiro dubbo service层相互调用
- Dubbo源码分析 之 netty调用获取返回值
- ListView自定义后,在onItemClick中getChildAt返回null问题
- ListView自定义后,在onItemClick中getChildAt返回null问题
- mybatis insert 插入数据成功后返回值为 null
- ListView自定义后,在onItemClick中getChildAt返回null问题
- Ubuntu su 进不去root用户
- 【bzoj1143 CTSC2008】祭祀river(最大独立集--二分图匹配)
- button & input type="button"
- 计算系数
- 解决One or more constraints have not been satisfied问题
- Dubbo调用Service后返回null
- MFC基于单文档菜单栏调用对话框的实现
- public、protected、friendly、private
- 欢迎使用CSDN-markdown编辑器
- View Layers
- 08_I/O输入输出流、文件重定向、格式控制、标准输入输出、 串流类、 文件操作、多线程
- android状态栏和标题栏的隐藏
- php php_openssl.dll作用
- 深度学习笔记——RNN(LSTM、GRU、双向RNN)学习总结