• springboot+mybatisPlus 配置多数据源--转载


    https://blog.csdn.net/u012075383/article/details/79304178

    踩坑记录,当自己需要写sql的时候,绑定Dao方法失败,原因是yml里面配置的xml扫面路径也要用java代码配置。

    2020-09-08 23:29:16.717 [http-nio-8111-exec-9] INFO  com.test.system.config.DataSourceAspect - 切换到db1 数据源...
    2020-09-08 23:29:16.729 [http-nio-8111-exec-9] ERROR org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.mdm.system.mapper.db1.ColumnInfoDao.getAllByList] with root cause
    org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.test.system.mapper.db1.InfoDao.getAllByList
       at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:235) ~[mybatis-3.5.3.jar:3.5.3]
    at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.<init>(MybatisMapperMethod.java:50) ~[mybatis-plus-core-3.3.0.jar:3.3.0]
    at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.lambda$cachedMapperMethod$0(MybatisMapperProxy.java:101) ~[mybatis-plus-core-3.3.0.jar:3.3.0]
    at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1705) ~[?:?]



    @Bean("sqlSessionFactory")
    public SqlSessionFactory sqlSessionFactory() throws Exception {
    MybatisSqlSessionFactoryBean sqlSessionFactory = new MybatisSqlSessionFactoryBean();
    sqlSessionFactory.setDataSource(multipleDataSource(db1(), db2()));
    sqlSessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:/mapper/*.xml"));

    MybatisConfiguration configuration = new MybatisConfiguration();
    configuration.setJdbcTypeForNull(JdbcType.NULL);
    configuration.setMapUnderscoreToCamelCase(true);
    configuration.setCacheEnabled(false);
    sqlSessionFactory.setConfiguration(configuration);
    //PerformanceInterceptor(),OptimisticLockerInterceptor()
    //添加分页功能
    sqlSessionFactory.setPlugins(new Interceptor[]{
    paginationInterceptor()
    });
    // sqlSessionFactory.setGlobalConfig(globalConfiguration()); //注释掉全局配置,因为在xml中读取就是全局配置
    return sqlSessionFactory.getObject();
    }

    添加上黄色标记部分,就能成功读取到xml了。(yml部分失效了。)
     
  • 相关阅读:
    centos 7.3 配置vnc 服务 图形界面登录
    安装vnc出现的问题
    HDFS文件系统的JAVA-API操作(一)
    kafka offset的存储问题
    kafka查询topic属性含义
    java静态类、静态方法、静态代码块,静态变量及实例方法,实例变量初始化顺序及内存管理,机制
    avg函数忽略null值
    为服务开启BBR加速
    正则表达式转义所有特殊符号
    Scala 运算符优先顺序
  • 原文地址:https://www.cnblogs.com/majw/p/13628415.html
Copyright © 2020-2023  润新知