springboot 加载依赖中的mapper.xml失败问题
项目结构
项目结构如上图,
整体来说是单服务项目,ors-gateway引用项目中其他模块如 ors-userInfo,ors-buildingInfo模块,只有ors-gateway有启动类,
springboot的配置文件,都是在ors-gateway模块中,启动ors-gateway应用
ors-gateway中的controller调用ors-buildingInfo中的service
该异常就是说,对的mapper已经加载到了,但是和mapper对应的mapper.xml没有加载,所以报没有绑定,截图如下
mapperLocations:classpath:mapper/**/*.xml 智能扫描本项目resources文件下 mapper.xml,很显然扫描不到ors-buildingInfo中的mapper.xml
那怎么才能加载到依赖jar中的mapper.xml呢?
这里就要这么写:
mybatis.mapperLocations: classpath*:mapper/*.xml
classpath*:读取本模块以及本模块依赖的jar包中的资源
classpath:只读取本模块的资源