zoukankan      html  css  js  c++  java
  • application.yml配置------------主要配置了单库水平分表操作

    https://blog.csdn.net/qq_36669347/article/details/107790213

    pom.xml 配置

    <dependencies>
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
    </dependency>

    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
    </dependency>

    <dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid-spring-boot-starter</artifactId>
    <version>1.1.22</version>
    </dependency>

    <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    </dependency>

    <dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>sharding-jdbc-spring-boot-starter</artifactId>
    <version>4.0.0-RC1</version>
    </dependency>

    <dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
    <version>3.4.1</version>
    </dependency>

    <dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    </dependency>
    <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <scope>test</scope>
    </dependency>
    </dependencies>

    jdbc.properties 配置

    spring.shardingsphere.datasource.names=m1

    #配置第一个数据源具体内容,包含连接池,驱动,地址,用户名和密码
    spring.shardingsphere.datasource.m1.type=com.alibaba.druid.pool.DruidDataSource
    spring.shardingsphere.datasource.m1.driver-class-name=com.mysql.cj.jdbc.Driver
    spring.shardingsphere.datasource.m1.url=jdbc:mysql://localhost:3306/course_db?serverTimezone=GMT%2B8
    spring.shardingsphere.datasource.m1.username=root
    spring.shardingsphere.datasource.m1.password=root

    spring.shardingsphere.sharding.tables.course.actual-data-nodes=m1.course_$->{1..2}


    # 指定course表里面主键cid 生成策略 SNOWFLAKE
    spring.shardingsphere.sharding.tables.course.key-generator.column=cid
    spring.shardingsphere.sharding.tables.course.key-generator.type=SNOWFLAKE

    # 指定表分片策略 约定cid值偶数添加到course_1表,如果cid是奇数添加到course_2表
    spring.shardingsphere.sharding.tables.course.table-strategy.inline.sharding-column=cid
    spring.shardingsphere.sharding.tables.course.table-strategy.inline.algorithm-expression=course_$->{cid % 2 + 1}

    # 打开sql输出日志
    spring.shardingsphere.props.sql.show=true

    spring.main.allow-bean-definition-overriding=true
    ————————————————
    版权声明:本文为CSDN博主「陨落星辰wjj」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/qq_36669347/article/details/107790213

  • 相关阅读:
    .Net Core微服务——Ocelot(2):集成Consul 老马
    .NET 微服务——CI/CD(1):Jenkins+Gitee自动构建 老马
    .Net Core——用SignalR撸个游戏 老马
    JUC之线程间的通信
    SpringBoot文章合集
    JUC之线程间定制化通信
    JUC之集合中的线程安全问题
    JUC文章合集
    JUC之Lock接口以及Synchronized回顾
    JUC概述
  • 原文地址:https://www.cnblogs.com/zhoading/p/15320859.html
Copyright © 2011-2022 走看看