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
为空,使用默认值