diff --git a/im-das/im-das-user/pom.xml b/im-das/im-das-user/pom.xml index 729f2e8..04cf859 100644 --- a/im-das/im-das-user/pom.xml +++ b/im-das/im-das-user/pom.xml @@ -57,17 +57,10 @@ org.apache.shardingsphere shardingsphere-jdbc-core-spring-boot-starter - ${shardingsphere.version} - mysql diff --git a/im-das/im-das-user/src/main/resources/application.properties b/im-das/im-das-user/src/main/resources/application.properties index 669fe39..b766c15 100644 --- a/im-das/im-das-user/src/main/resources/application.properties +++ b/im-das/im-das-user/src/main/resources/application.properties @@ -2,19 +2,27 @@ spring.profiles.active=${SPRING_PROFILES_ACTIVE:dev} # sharding-jdbc 配置 # 配置数据源 -spring.shardingsphere.datasource.names=db1 - -spring.shardingsphere.datasource.db1.type=com.zaxxer.hikari.HikariDataSource -spring.shardingsphere.datasource.db1.driver-class-name=com.mysql.cj.jdbc.Driver -spring.shardingsphere.datasource.db1.jdbc-url=jdbc:mysql://cd-cdb-mrz9fw80.sql.tencentcdb.com:61843/soim_db?serverTimezone=GMT%2B8 -spring.shardingsphere.datasource.db1.username=root -spring.shardingsphere.datasource.db1.password=sopod@2347# +spring.shardingsphere.datasource.names=ds1 +spring.shardingsphere.datasource.ds1.type=com.zaxxer.hikari.HikariDataSource +spring.shardingsphere.datasource.ds1.driver-class-name=com.mysql.cj.jdbc.Driver +spring.shardingsphere.datasource.ds1.jdbc-url=jdbc:mysql://cd-cdb-mrz9fw80.sql.tencentcdb.com:61843/soim_db?serverTimezone=GMT%2B8 +spring.shardingsphere.datasource.ds1.username=root +spring.shardingsphere.datasource.ds1.password=sopod@2347# # 分表 -spring.shardingsphere.sharding.tables.im_user.actual-data-nodes=db1.im_user_$->{0..2} -# 指定t_user表的分片策略,分片策略包括分片键和分片算法 -spring.shardingsphere.sharding.tables.im_user.table-strategy.inline.sharding-column=id -spring.shardingsphere.sharding.tables.im_user.table-strategy.inline.algorithm-expression=im_user_$->{id % 3} +#spring.shardingsphere.sharding.tables.im_user.actual-data-nodes=db1.im_user_$->{0..2} +## 指定im_user表的分片策略,分片策略包括分片键和分片算法 +#spring.shardingsphere.sharding.tables.im_user.table-strategy.inline.sharding-column=id +#spring.shardingsphere.sharding.tables.im_user.table-strategy.inline.algorithm-expression=im_user_$->{id % 3} + +# 5.1.0 分表 +# https://github.com/apache/shardingsphere/blob/master/examples/shardingsphere-jdbc-example/single-feature-example/sharding-example/sharding-raw-jdbc-example/src/main/resources/META-INF/sharding-tables.yaml +spring.shardingsphere.rules.sharding.tables.im_user.actual-data-nodes=ds1.im_user_$->{0..2} +spring.shardingsphere.rules.sharding.tables.im_user.table-strategy.standard.sharding-column=id +spring.shardingsphere.rules.sharding.tables.im_user.table-strategy.standard.sharding-algorithm-name=im-user-inline +spring.shardingsphere.rules.sharding.binding-tables=im_user +spring.shardingsphere.rules.sharding.sharding-algorithms.im-user-inline.type=INLINE +spring.shardingsphere.rules.sharding.sharding-algorithms.im-user-inline.props.algorithm-expression=im_user_$->{id % 3} # 打开sharding-jdbc sql输出日志 -spring.shardingsphere.props.sql.show=true +spring.shardingsphere.props.sql-show=true diff --git a/im-das/im-das-user/src/main/resources/application.yml b/im-das/im-das-user/src/main/resources/application.yml index bbf35f3..605fdbe 100644 --- a/im-das/im-das-user/src/main/resources/application.yml +++ b/im-das/im-das-user/src/main/resources/application.yml @@ -8,3 +8,4 @@ dubbo: mybatis-plus: mapper-locations: classpath:mapper/*.xml + diff --git a/im-das/im-das-user/src/test/java/nets/sopod/soim/das/user/test/DasUserApplicationTest.java b/im-das/im-das-user/src/test/java/nets/sopod/soim/das/user/test/DasUserApplicationTest.java index 347915a..169c44c 100644 --- a/im-das/im-das-user/src/test/java/nets/sopod/soim/das/user/test/DasUserApplicationTest.java +++ b/im-das/im-das-user/src/test/java/nets/sopod/soim/das/user/test/DasUserApplicationTest.java @@ -26,8 +26,8 @@ public class DasUserApplicationTest { @Test public void test() { ImUser user1 = new ImUser() - .setId(1L) - .setUsername("閲庡瀛") + .setId(4L) + .setUsername("閲庡瀛2") .setPassword("123456") .setPhone("17882451908") .setCreateTime(ImClock.date()); diff --git a/pom.xml b/pom.xml index d3150c1..439096b 100644 --- a/pom.xml +++ b/pom.xml @@ -37,7 +37,7 @@ 5.1.9.RELEASE 3.0.5 4.2.0 - 5.0.1 + 5.1.0 @@ -157,16 +157,16 @@ HikariCP 5.0.1 + + org.apache.shardingsphere + shardingsphere-sharding-spring-boot-starter + ${shardingsphere.version} + org.apache.shardingsphere shardingsphere-jdbc-core-spring-boot-starter ${shardingsphere.version} - com.baomidou mybatis-plus-boot-starter