Mode

配置项说明

Standalone mode

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:shardingsphere="http://shardingsphere.apache.org/schema/shardingsphere/datasource"
  5. xmlns:standalone="http://shardingsphere.apache.org/schema/shardingsphere/mode-repository/standalone"
  6. xsi:schemaLocation="http://www.springframework.org/schema/beans
  7. http://www.springframework.org/schema/beans/spring-beans.xsd
  8. http://shardingsphere.apache.org/schema/shardingsphere/datasource
  9. http://shardingsphere.apache.org/schema/shardingsphere/datasource/datasource.xsd
  10. http://shardingsphere.apache.org/schema/shardingsphere/mode-repository/standalone
  11. http://shardingsphere.apache.org/schema/shardingsphere/mode-repository/standalone/repository.xsd">
  12. <standalone:repository id="standaloneRepository" type="File">
  13. <props>
  14. <prop key="path">target</prop>
  15. </props>
  16. </standalone:repository>
  17. <shardingsphere:data-source id="shardingDatabasesTablesDataSource" data-source-names="demo_ds_0, demo_ds_1" rule-refs="shardingRule" schema-name="sharding_db">
  18. <shardingsphere:mode type="Standalone" repository-ref="standaloneRepository" overwrite="true"/>
  19. </shardingsphere:data-source>
  20. </beans>

<standalone:repository />

名称类型说明
id属性Standalone 模式实例名称
type属性Standalone 配置持久化类型。如:File
props (?)属性Standalone 配置持久化的属性 如:path 路径

<shardingsphere:data-source />

名称类型说明
schema-name (?)属性JDBC 数据源别名,该参数可实现 JDBC 与 PROXY 共享配置

Cluster mode

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:shardingsphere="http://shardingsphere.apache.org/schema/shardingsphere/datasource"
  5. xmlns:cluster="http://shardingsphere.apache.org/schema/shardingsphere/mode-repository/cluster"
  6. xsi:schemaLocation="http://www.springframework.org/schema/beans
  7. http://www.springframework.org/schema/beans/spring-beans.xsd
  8. http://shardingsphere.apache.org/schema/shardingsphere/datasource
  9. http://shardingsphere.apache.org/schema/shardingsphere/datasource/datasource.xsd
  10. http://shardingsphere.apache.org/schema/shardingsphere/mode-repository/cluster
  11. http://shardingsphere.apache.org/schema/shardingsphere/mode-repository/cluster/repository.xsd">
  12. <cluster:repository id="clusterRepository" type="Zookeeper" namespace="regCenter" server-lists="localhost:3182">
  13. <props>
  14. <prop key="max-retries">3</prop>
  15. <prop key="operation-timeout-milliseconds">1000</prop>
  16. </props>
  17. </cluster:repository>
  18. <shardingsphere:data-source id="shardingDatabasesTablesDataSource" data-source-names="demo_ds_0, demo_ds_1" rule-refs="shardingRule" schema-name="sharding_db">
  19. <shardingsphere:mode type="Cluster" repository-ref="clusterRepository" overwrite="true"/>
  20. </shardingsphere:data-source>
  21. </beans>

<cluster:repository />

名称类型说明
id属性Cluster 模式实例名称
type属性Cluster 模式类型。如:ZooKeeper, Etcd
namespace属性Cluster 模式命名空间
server-lists属性Zookeeper 或 Etcd 服务列表。包括 IP 地址和端口号。多个地址用逗号分隔。如: host1:2181,host2:2181
props (?)属性配置本实例需要的其他参数,例如 ZooKeeper 的连接参数等

<shardingsphere:data-source />

名称类型说明
schema-name (?)属性JDBC 数据源别名,该参数可实现 JDBC 与 PROXY 共享配置