spring boot多模块,请求时报错如下:Invalid bound statement (not found)

问题

当发起一个请求时报错如下:Invalid bound statement (not found): com.xxx.xxx.configcenter.common.mapper.ConfigDataMapper.saveConfigData

场景

本人的项目是一个多模块的项目,其中模块B依赖模块A,模块A的application.yml中配置如下:

mybatis:
  mapper-locations: classpath:mappers/*.xml

而模块B中无此配置,当针对模块B的请求在模块B代码中调用模块A的resources下面的mappers/*.xml时报错,于是就出现了上面的问题

原因

mapper-locations: classpath*:mappers/*.xml这个配置,只会扫描启动模块resources下的mappers/*.xml配置,并不会对其它模块进行扫描

解决

将模块A中的配置改为如下,即在classpath后面紧跟一个星号("*"), 这样就会加载所有模块resources下的mappers/*.xml配置

mybatis:
  mapper-locations: classpath*:mappers/*.xml

 

你可能感兴趣的:(09,springBoot,10,Mybatis)