zoukankan      html  css  js  c++  java
  • 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部分失效了。)
     
  • 相关阅读:
    EntityFramework 启用迁移 EnableMigrations 报异常 "No context type was found in the assembly"
    JAVA 访问FTP服务器示例(2)
    NuGet Package Manager 更新错误解决办法
    JAVA 访问FTP服务器示例(1)
    RemoteAttribute 的使用问题
    诡异的 javascript 变量
    javascript apply用法
    Babun 中文乱码
    GSM呼叫过程
    转站博客园
  • 原文地址:https://www.cnblogs.com/majw/p/13628415.html
Copyright © 2011-2022 走看看