栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

mybatis多数据源

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

mybatis多数据源

多数据源配置
  • mybatis多数据源配置(依赖引入省略)
    • 配置文件
    • springboot DB1 config 多文件形式
    • springboot DB2 config文件

mybatis多数据源配置(依赖引入省略) 配置文件
spring:
  datasource:
    db1:
      url: jdbc:mysql://127.0.0.1:3306/db?useSSL=false&serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8
      username: root1
      password: 123456
      driver-class-name: com.mysql.cj.jdbc.Driver
      type: com.alibaba.druid.pool.DruidDataSource
    db2:
      url: jdbc:mysql://127.0.0.2:3306/db?useSSL=false&serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8
      username: root2
      password: 123456
      driver-class-name: com.mysql.cj.jdbc.Driver
      type: com.alibaba.druid.pool.DruidDataSource
      
mybatis-plus:
  configuration:
    map-underscore-to-camel-case: true
    #    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
    #配置输出到日志文件--生产环境下还是需要谨慎考虑一下是否开启sql日志,因为日志记录是会进行频繁的IO,会有一定的性能损耗。
    #log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl
  mapper-locations: classpath:mapper
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor()
    {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }
}

springboot DB2 config文件
复制上述文件更改bean 名称以及文件名即可 
对应创建mapper 下文件 目录 db1 以及 db2
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1013444.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号