天天看點

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,問題解決。