今天应用服务启动式,出现一个异常
lineNumber: 1; columnNumber: 589; 元素内容必须由格式正确的字符数据或标记组成。
,经过一步步排查总算解决问题了。
异常排查
应用服务启动时,堆栈如下:
从堆栈我们可以发现JobPoolDeliveryMapper
这个类中xml中有不符合xml的语法错误。然后我们把断点设置到这个org.apache.ibatis.parsing.XPathParser#createDocument
这个方法中,断点如下,然后重新启动应用服务发现堆栈。
从异常信息中我们发现异常引起的动态SQL如下:
然后如上图,找到这个str字符串,找到字符,展开找到590个字符,发现在 <> 附近引起。
这时候我们找到原始的SQL
@Select("<script>" +
" select count(*) totalMatchCount " +
" ,sum(case when delivery_tag = 2 and confirm_tag =1 then 1 else 0 end) + sum(case when confirm_tag = 2 and charge_type = 1 then 1 else 0 end) currentTaskCount " +
" ,sum(case when delivery_tag = 2 and confirm_tag =1 then 1 else 0 end) deliveryMatchCount " +
" ,sum(case when confirm_tag = 2 then 1 else 0 end) confirmCount " +
" ,sum(case when confirm_tag = 2 and charge_type = 1 then 1 else 0 end) freeConfirmCount " +
" ,sum(case when confirm_tag = 2 and charge_type = 2 then 1 else 0 end) payConfirmCount " +
" ,job_pool_id jobPoolId from job_pool_delivery where state <> 0 and delivery_finished = 1 " +
" and job_pool_id in <foreach item='item' index='index' collection='jobPoolIds' open='(' separator=',' close=')'> #{item} </foreach>" +
" group by job_pool_id " +
" </script>")
List<JobProxyTaskCountBO> listJobProxyTaskCount(@Param("jobPoolIds") List<Long> jobPoolIds);
猜测是<> 这个查询过滤条件有问题,然后增加上 转义标签
<![CDATA[state <> 0]]>
,然后重启项目解决。
总结
如上是一个排查思路,通过定位对应的mapper,然后进而定位到某个sql,进而定位到引起异常某个字符串附近,最终通过定位排查解决问题。