天天看点

SpringBoot整合Mybatis-Plus报错:org.springframework.core.NestedIOException错误分析解决

错误

SpringBoot整合Mybatis-Plus,报错:

Caused by: org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/baomidou/mybatisplus/spring/boot/starter/MybatisPlusAutoConfiguration.class]: Bean instantiation via factory method failed; 
nested exception is org.springframework.beans.BeanInstantiationException: 
Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: 
Factory method 'sqlSessionFactory' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 
'file [D:\IdeaProjects\Great-Wall-New\gwssi-bjdbc\gwssi-grant\gwssi-grant-common\target\classes\cn\gwssi\grant\common\block\dao\mapping\BlockAbnormalInfoRecordMapper.xml]'; 
nested exception is java.lang.NullPointerException      

分析

将报错抽取出来,关键一行在于:

org.springframework.core.NestedIOException: 
Failed to parse mapping resource: 'file [D:\IdeaProjects\Great-Wall-New\gwssi-bjdbc\gwssi-grant\gwssi-grant-common\target\classes\cn\gwssi\grant\common\block\dao\mapping\BlockAbnormalInfoRecordMapper.xml]';       

出错的是BlockAbnormalInfoRecordMapper.xml,找到出错的接口和对应的映射文件。

经过排查发现,由于粗心,接口继承里泛型写成了 BlockAbnormalInfoRecordMapper。

SpringBoot整合Mybatis-Plus报错:org.springframework.core.NestedIOException错误分析解决

解决

将泛型改成正确的实体类:

SpringBoot整合Mybatis-Plus报错:org.springframework.core.NestedIOException错误分析解决

OK,问题解决。