Maven项目扫描不到子模块mybatis-plus XML mapper文件问题的解决方法
起因
工作中有个需求需要把公共的service提到common模块中。提取完成后编译运行并没有报错,但是调用相关方法时提示mapper报错,原因是找不到mapper接口中方法对应的xml内的映射关系
原因
主模块的application.yml配置文件内,mybatis-plus的mapper-locations配置项用的是classpath,这只会扫描当前模块的mapper,而改为classpath*则会扫描所有依赖内的文件
在mybatis-plus官方文档内有mapper-locations配置的说明,该配置项的默认值就是classpath*:/mapper/**/*.xml,由于我们修改了该配置项为classpath*:mapper/*.xml,导致出现该错误
解决方法
按如下方式修改mybatis-plus.mapper-locations即可

保持mybatis-plus.mapper-locations为空,使用默认值