模式配置

配置项说明

命名空间:http://shardingsphere.apache.org/schema/shardingsphere/datasource/datasource-5.1.0.xsd

<shardingsphere:mode />

名称类型说明默认值
type属性运行模式类型。可选配置:Memory、Standalone、Cluster
repository-ref (?)属性持久化仓库 Bean 引用。Memory 类型无需持久化
overwrite (?)属性是否使用本地配置覆盖持久化配置false

内存模式

缺省配置。

配置示例

  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. xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. http://www.springframework.org/schema/beans/spring-beans.xsd
  7. http://shardingsphere.apache.org/schema/shardingsphere/datasource
  8. http://shardingsphere.apache.org/schema/shardingsphere/datasource/datasource.xsd">
  9. <shardingsphere:data-source id="ds" schema-name="foo_schema" data-source-names="..." rule-refs="..." />
  10. </beans>

单机模式

配置项说明

命名空间:http://shardingsphere.apache.org/schema/shardingsphere/mode-repository/standalone/repository-5.0.0.xsd

<standalone:repository />

名称类型说明
id属性持久化仓库 Bean 名称
type属性持久化仓库类型
props (?)标签持久化仓库所需属性

配置示例

  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="ds" schema-name="foo_schema" data-source-names="..." rule-refs="..." >
  18. <shardingsphere:mode type="Standalone" repository-ref="standaloneRepository" overwrite="true" />
  19. </shardingsphere:data-source>
  20. </beans>

集群模式

配置项说明

命名空间:http://shardingsphere.apache.org/schema/shardingsphere/mode-repository/cluster/repository-5.0.0.xsd

<cluster:repository />

名称类型说明
id属性持久化仓库 Bean 名称
type属性持久化仓库类型
namespace属性注册中心命名空间
server-lists属性注册中心连接地址
props (?)标签持久化仓库所需属性

配置示例

  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="ds" schema-name="foo_schema" data-source-names="..." rule-refs="...">
  19. <shardingsphere:mode type="Cluster" repository-ref="clusterRepository" overwrite="true" />
  20. </shardingsphere:data-source>
  21. </beans>

持久化仓库类型的详情,请参见内置持久化仓库类型列表