Spring Boot 集成 Mybatis 多数据源配置后出现 Invalid bound statement (not found)

时间:2022-07-22
本文章向大家介绍Spring Boot 集成 Mybatis 多数据源配置后出现 Invalid bound statement (not found),主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

通常导致这种原因的大致有以下这几种情况:

  1. mapper的namespace 有问题
  2. xxMapper的方法在xxMapper.xml中没有,调用那个方法就报错
  3. 没有正确配置ResultMap,或者只配置ResultType!

我这情况跟上面不同。

使用单独数据源是可以的,只有一个数据源的mapper正常,一起使用就报错。

项目是使用xml方式配置数据源的,Spring Boot 集成的mybatis starter里面的 MybatisAutoConfiguration 自动加载了 mapper,导致另外的数据源对应的mapper没有出来?

排除 MybatisAutoConfiguration 自动加载:

@SpringBootApplication(scanBasePackages = {"com.alibaba.ovs.selection"},exclude = MybatisAutoConfiguration.class)
@ImportResource({
        "classpath*:sentinel-tracer.xml",
        "classpath:adsDataSource.xml",
        "classpath:dataSource.xml",
        "classpath:keycenter.xml"
})
public class Application {

    public static void main(String[] args) {
        PandoraBootstrap.run(args);
        SpringApplication.run(Application.class, args);
        PandoraBootstrap.markStartupAndWait();
    }
}

解决