錯誤
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。
![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLicmbw5CZmZGNyIjZyI2YmZDZ3ITOlBTO0IWZ0cDOkFmNzEGMm9CX5d2bs92Yl1iclB3bsVmdlR2LcNWaw9CXt92Yu4GZjlGbh5yYjV3Lc9CX6MHc0RHaiojIsJye.png)
解決
将泛型改成正确的實體類:
OK,問題解決。