Apache ShardingSphere 示例项目教程

Apache ShardingSphere 示例项目教程

shardingsphere-exampleSharding-Sphere examples项目地址:https://gitcode.com/gh_mirrors/shar/shardingsphere-example

1. 项目的目录结构及介绍

Apache ShardingSphere 示例项目 (shardingsphere-example) 是一个独立的 Maven 项目,位于 Apache ShardingSphere 项目的 examples 目录下。项目的目录结构如下:

shardingsphere-example
├── example-core
│   ├── config-utility
│   ├── example-api
│   ├── example-raw-jdbc
│   ├── example-spring-jpa
│   └── example-spring-mybatis
├── shardingsphere-jdbc-example
│   ├── sharding-example
│   │   ├── sharding-raw-jdbc-example
│   │   ├── sharding-spring-boot-jpa-example
│   │   └── sharding-spring-boot-mybatis-example
│   └── ...
├── shardingsphere-proxy-example
│   └── ...
├── shardingsphere-parser-example
│   └── ...
└── ...

主要模块介绍

  • example-core: 核心示例模块,包含配置工具和不同框架的示例。

    • config-utility: 配置工具模块。
    • example-api: API 示例模块。
    • example-raw-jdbc: 原生 JDBC 示例模块。
    • example-spring-jpa: Spring JPA 示例模块。
    • example-spring-mybatis: Spring MyBatis 示例模块。
  • shardingsphere-jdbc-example: ShardingSphere-JDBC 示例模块,包含分片示例。

    • sharding-example: 分片示例模块。
      • sharding-raw-jdbc-example: 原生 JDBC 分片示例。
      • sharding-spring-boot-jpa-example: Spring Boot JPA 分片示例。
      • sharding-spring-boot-mybatis-example: Spring Boot MyBatis 分片示例。
  • shardingsphere-proxy-example: ShardingSphere-Proxy 示例模块。

  • shardingsphere-parser-example: ShardingSphere-Parser 示例模块。

2. 项目的启动文件介绍

启动文件示例

sharding-spring-boot-mybatis-example 为例,启动文件通常位于 src/main/java 目录下,例如:

package org.apache.shardingsphere.example.sharding.spring.boot.mybatis;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class ShardingSpringBootMybatisExample {

    public static void main(String[] args) {
        SpringApplication.run(ShardingSpringBootMybatisExample.class, args);
    }
}

启动步骤

  1. 克隆项目: 从 GitHub 克隆项目到本地。
  2. 构建项目: 使用 Maven 构建项目,执行 mvn clean install
  3. 导入 IDE: 将项目导入到 IDE 中。
  4. 配置数据库: 准备一个可管理的数据库环境,如本地 MySQL。
  5. 执行启动文件: 运行启动文件中的 main 方法。

3. 项目的配置文件介绍

配置文件示例

sharding-spring-boot-mybatis-example 为例,配置文件通常位于 src/main/resources 目录下,例如:

spring:
  shardingsphere:
    datasource:
      names: ds0, ds1
      ds0:
        type: com.zaxxer.hikari.HikariDataSource
        driver-class-name: com.mysql.cj.jdbc.Driver
        jdbc-url: jdbc:mysql://localhost:3306/ds0
        username: root
        password: root
      ds1:
        type: com.zaxxer.hikari.HikariDataSource
        driver-class-name: com.mysql.cj.jdbc.Driver
        jdbc-url: jdbc:mysql://localhost:3306/ds1
        username: root
        password: root
    sharding:
      tables:
        t_order:
          actual-data

shardingsphere-exampleSharding-Sphere examples项目地址:https://gitcode.com/gh_mirrors/shar/shardingsphere-example

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蓬为宜

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值