ShardingSphere之Sharding-JDBC与Spr

2019-05-05  本文已影响0人  飞狗未来

ShardingSphere简介

SpringBoot配置

<dependency>
    <groupId>io.shardingsphere</groupId>
    <artifactId>sharding-jdbc-core</artifactId>
    <version>3.1.0</version>
</dependency>
<dependency>
    <groupId>io.shardingsphere</groupId>
    <artifactId>sharding-jdbc-spring-boot-starter</artifactId>
    <version>3.1.0</version>
</dependency>

SpringBoot工程目录结构

目录结构

application.properties

server.port=8082


spring.profiles.active=sharding-tables
#spring.profiles.active=master-slave

mybatis.mapper-locations=classpath:mapping/*.xml
mybatis.type-aliases-package=com.lx.model

#pagehelper分页插件

pagehelper.helperDialect=mysql
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql

application-sharding-tables.properties

sharding.jdbc.datasource.names=ds

sharding.jdbc.datasource.ds.type=com.alibaba.druid.pool.DruidDataSource
sharding.jdbc.datasource.ds.driver-class-name=com.mysql.jdbc.Driver
sharding.jdbc.datasource.ds.url=jdbc:mysql://127.0.0.1:3306/ds0
sharding.jdbc.datasource.ds.username=root
sharding.jdbc.datasource.ds.password=root

sharding.jdbc.config.sharding.tables.note.actual-data-nodes=ds.note$->{0..1}
sharding.jdbc.config.sharding.tables.note.table-strategy.inline.sharding-column=id
sharding.jdbc.config.sharding.tables.note.table-strategy.inline.algorithm-expression=note$->{id % 2}
sharding.jdbc.config.sharding.tables.note.key-generator-column-name=id

分库分表中间件对比

附录

  1. ShardingSphere首页
  2. ShardingSphere3.x版本文档
  3. ShardingSphere4.x版本文档
  4. ShardingSphere例子
  5. Mycat权威指南
  6. Mycat
上一篇 下一篇

猜你喜欢

热点阅读