shardingsphere读写分离

文章介绍了如何在项目中添加ShardingSphere和Druid的依赖来实现数据库的读写分离,配置了Spring的ShardingSphere数据源,包括主库和从库的Druid数据源设置,并展示了因分组查询引发的MyBatis错误及解决方案。
摘要由CSDN通过智能技术生成
#增加jar包
<!-- 读写分离 -->
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>sharding-jdbc-spring-boot-starter</artifactId>
<version>4.1.1</version>
</dependency>

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.2.8</version>
</dependency>
# Spring配置
spring:
  shardingsphere:
    datasource:
      names: master,slave0
      master:
        type: com.alibaba.druid.pool.DruidDataSource
        driver-class-name: com.mysql.cj.jdbc.Driver
        url: jdbc:mysql://127.0.0.1:3309/xxxx?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
        username: root  
        password: 123456
        initial-size: 10
        min-idle: 10
        maxActive: 100
        maxWait: 60000
        timeBetweenEvictionRunsMillis: 60000
        minEvictableIdleTimeMillis: 300000
        validationQuery: SELECT 1
        testWhileIdle: true
        testOnBorrow: false
        testOnReturn: false
        poolPreparedStatements: true
        maxPoolPreparedStatementPerConnectionSize: 20
        filter: stat,wall,log4j2
        connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
      slave0:
        type: com.alibaba.druid.pool.DruidDataSource
        driver-class-name: com.mysql.cj.jdbc.Driver
        url: jdbc:mysql://127.0.01:3310/xxxx?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
        username: root  
        password: 123456
        filters: stat,wall,log4j2
        connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
    props:
      sql:
        show: true
    masterslave:
      load-balance-algorithm-type: round_robin
      name: ms
      master-data-source-name: master
      slave-data-source-names: slave0

MyBatis报错 : Caused by: java.lang.IllegalStateException: Can not find owner from table 报错前SQL语句

select * from (
    select * from test a
)  b GROUP BY b.id

修改后前SQL语句,注:一定要注意分组后的列

select * from (
    select * from test a
)  b GROUP BY id

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值