Spring namespace configuration change history

ShardingSphere-5.0.0-beta

Sharding

Configuration Item Explanation

Namespace: http://shardingsphere.apache.org/schema/shardingsphere/sharding/sharding-5.0.0.xsd

<sharding:rule />

NameTypeDescription
idAttributeSpring Bean Id
table-rules (?)TagSharding table rule configuration
auto-table-rules (?)TagAutomatic sharding table rule configuration
binding-table-rules (?)TagBinding table rule configuration
broadcast-table-rules (?)TagBroadcast table rule configuration
default-database-strategy-ref (?)AttributeDefault database strategy name
default-table-strategy-ref (?)AttributeDefault table strategy name
default-key-generate-strategy-ref (?)AttributeDefault key generate strategy name
default-sharding-column (?)AttributeDefault sharding column name

<sharding:table-rule />

NameTypeDescription
logic-tableAttributeLogic table name
actual-data-nodesAttributeDescribe data source names and actual tables, delimiter as point, multiple data nodes separated with comma, support inline expression. Absent means sharding databases only.
actual-data-sourcesAttributeData source names for auto sharding table
database-strategy-refAttributeDatabase strategy name for standard sharding table
table-strategy-refAttributeTable strategy name for standard sharding table
sharding-strategy-refAttributesharding strategy name for auto sharding table
key-generate-strategy-refAttributeKey generate strategy name

<sharding:binding-table-rules />

NameTypeDescription
binding-table-rule (+)TagBinding table rule configuration

<sharding:binding-table-rule />

NameTypeDescription
logic-tablesAttributeBinding table name, multiple tables separated with comma

<sharding:broadcast-table-rules />

NameTypeDescription
broadcast-table-rule (+)TagBroadcast table rule configuration

<sharding:broadcast-table-rule />

NameTypeDescription
tableAttributeBroadcast table name

<sharding:standard-strategy />

NameTypeDescription
idAttributeStandard sharding strategy name
sharding-columnAttributeSharding column name
algorithm-refAttributeSharding algorithm name

<sharding:complex-strategy />

NameTypeDescription
idAttributeComplex sharding strategy name
sharding-columnsAttributeSharding column names, multiple columns separated with comma
algorithm-refAttributeSharding algorithm name

<sharding:hint-strategy />

NameTypeDescription
idAttributeHint sharding strategy name
algorithm-refAttributeSharding algorithm name

<sharding:none-strategy />

NameTypeDescription
idAttributeSharding strategy name

<sharding:key-generate-strategy />

NameTypeDescription
idAttributeKey generate strategy name
columnAttributeKey generate column name
algorithm-refAttributeKey generate algorithm name

<sharding:sharding-algorithm />

NameTypeDescription
idAttributeSharding algorithm name
typeAttributeSharding algorithm type
props (?)TagSharding algorithm properties

<sharding:key-generate-algorithm />

NameTypeDescription
idAttributeKey generate algorithm name
typeAttributeKey generate algorithm type
props (?)TagKey generate algorithm properties

Please refer to Built-in Sharding Algorithm List and Built-in Key Generate Algorithm List for more details about type of algorithm.

Attention

Inline expression identifier can use ${...} or $->{...}, but ${...} is conflict with spring placeholder of properties, so use $->{...} on spring environment is better.

Readwrite-Splitting

Configuration Item Explanation

Namespace: http://shardingsphere.apache.org/schema/shardingsphere/readwrite-splitting/readwrite-splitting-5.0.0.xsd

<readwrite-splitting:rule />

NameTypeDescription
idAttributeSpring Bean Id
data-source-rule (+)TagReadwrite-splitting data source rule configuration

<readwrite-splitting:data-source-rule />

NameTypeDescription
idAttributeReadwrite-splitting data source rule name
write-data-source-nameAttributeWrite data source name
read-data-source-namesAttributeRead data source names, multiple data source names separated with comma
load-balance-algorithm-refAttributeLoad balance algorithm name

<readwrite-splitting:load-balance-algorithm />

NameTypeDescription
idAttributeLoad balance algorithm name
typeAttributeLoad balance algorithm type
props (?)TagLoad balance algorithm properties

Please refer to Built-in Load Balance Algorithm List for more details about type of algorithm. Please refer to Use Norms for more details about query consistent routing.

Encryption

Configuration Item Explanation

Namespace: http://shardingsphere.apache.org/schema/shardingsphere/encrypt/encrypt-5.0.0.xsd

<encrypt:rule />

NameTypeDescriptionDefault Value
idAttributeSpring Bean Id
queryWithCipherColumn (?)AttributeWhether query with cipher column for data encrypt. User you can use plaintext to query if havetrue
table (+)TagEncrypt table configuration

<encrypt:table />

NameTypeDescription
nameAttributeEncrypt table name
column (+)TagEncrypt column configuration

<encrypt:column />

NameTypeDescription
logic-columnAttributeColumn logic name
cipher-columnAttributeCipher column name
assisted-query-column (?)AttributeAssisted query column name
plain-column (?)AttributePlain column name
encrypt-algorithm-refAttributeEncrypt algorithm name

<encrypt:encrypt-algorithm />

NameTypeDescription
idAttributeEncrypt algorithm name
typeAttributeEncrypt algorithm type
props (?)TagEncrypt algorithm properties

Please refer to Built-in Encrypt Algorithm List for more details about type of algorithm.

Shadow-DB

Configuration Item Explanation

Namespace: http://shardingsphere.apache.org/schema/shardingsphere/shadow/shadow-5.0.0.xsd

<shadow:rule />

NameTypeDescription
idAttributeSpring Bean Id
columnAttributeShadow column name
mappings(?)TagMapping relationship between production database and shadow database

<shadow:mapping />

NameTypeDescription
product-data-source-nameAttributeProduction database name
shadow-data-source-nameAttributeShadow database name

4.x

Sharding

Configuration Item Explanation

Namespace: http://shardingsphere.apache.org/schema/shardingsphere/sharding/sharding.xsd

<sharding:data-source />

NameTypeDescription
idAttributeSpring Bean Id
sharding-ruleTagSharding rule configuration
props (?)TagProperties

<sharding:sharding-rule />

NameTypeDescription
data-source-namesAttributeData source Bean list with comma separating multiple Beans
table-rulesTagConfiguration objects of table sharding rules
binding-table-rules (?)TagBinding table rule list
broadcast-table-rules (?)TagBroadcast table rule list
default-data-source-name (?)AttributeTables without sharding rules will be located through default data source
default-database-strategy-ref (?)AttributeDefault database sharding strategy, which corresponds to id of sharding:xxx-strategy; default means the database is not split
default-table-strategy-ref (?)AttributeDefault table sharding strategy,which corresponds to id of sharding:xxx-strategy; default means the database is not split
default-key-generator (?)AttributeDefault key generator configuration, use user-defined ones or built-in ones, e.g. SNOWFLAKE/UUID. Default key generator is org.apache.shardingsphere.core.keygen.generator.impl.SnowflakeKeyGenerator
encrypt-rule (?)TagEncrypt rule

<sharding:table-rules />

NameTypeDescription
table-rule (+)TagConfiguration objects of table sharding rules

<sharding:table-rule />

NameTypeDescription
logic-tableAttributeLogic table name
actual-data-nodes (?)AttributeDescribe data source names and actual tables, delimiter as point, multiple data nodes separated with comma, support inline expression. Absent means sharding databases only.
database-strategy-refAttributeDatabase strategy name for standard sharding table
table-strategy-refAttributeTable strategy name for standard sharding table
key-generate-strategy-refAttributeKey generate strategy name

<sharding:binding-table-rules />

NameTypeDescription
binding-table-rule (+)TagBinding table rule configuration

<sharding:binding-table-rule />

NameTypeDescription
logic-tablesAttributeBinding table name, multiple tables separated with comma

<sharding:broadcast-table-rules />

NameTypeDescription
broadcast-table-rule (+)TagBroadcast table rule configuration

<sharding:broadcast-table-rule />

NameTypeDescription
tableAttributeBroadcast table name

<sharding:standard-strategy />

NameTypeDescription
idAttributeStandard sharding strategy name
sharding-columnAttributeSharding column name
precise-algorithm-ref (?)AttributePrecise algorithm reference, applied in = and IN; the class needs to implement PreciseShardingAlgorithm interface
range-algorithm-ref (?)AttributeRange algorithm reference, applied in BETWEEN; the class needs to implement RangeShardingAlgorithm interface

<sharding:complex-strategy />

NameTypeDescription
idAttributeComplex sharding strategy name
sharding-columnsAttributeSharding column names, multiple columns separated with comma
algorithm-refAttributeComplex sharding algorithm reference; the class needs to implement ComplexKeysShardingAlgorithm interface

<sharding:inline-strategy />

NameTypeDescription
idAttributeSpring Bean Id
sharding-columnsAttributeSharding column names, multiple columns separated with comma
algorithm-refAttributeSharding algorithm inline expression, which needs to conform to groovy statements

<sharding:hint-database-strategy />

NameTypeDescription
idAttributeHint sharding strategy name
algorithm-refAttributeHint sharding algorithm; the class needs to implement HintShardingAlgorithm interface

<sharding:none-strategy />

NameTypeDescription
idAttributeSpring Bean Id

<sharding:key-generator />

NameTypeDescription
columnAttributeAuto-increment column name
typeAttributeAuto-increment key generator Type; self-defined generator or internal Type generator (SNOWFLAKE/UUID) can both be selected
props-refAttributeThe Property configuration reference of key generators

Properties Property configuration that can include these properties of these key generators.

SNOWFLAKE | Name | Data Type | Explanation | | ————- | ——— | ————————— | | worker.id (?) | long | The unique id for working machine, the default value is 0 | | max.tolerate.time.difference.milliseconds (?) | long | The max tolerate time for different server’s time difference in milliseconds, the default value is 10 | | max.vibration.offset (?) | int | The max upper limit value of vibrate number, range [0, 4096), the default value is 1. Notice: To use the generated value of this algorithm as sharding value, it is recommended to configure this property. The algorithm generates key mod 2^n (2^n is usually the sharding amount of tables or databases) in different milliseconds and the result is always 0 or 1. To prevent the above sharding problem, it is recommended to configure this property, its value is (2^n)-1 |

<sharding:encrypt-rules />

NameTypeDescription
encryptor-rule (+)TagEncryptor rule

<sharding:encrypt-rule />

NameTypeDescription
encrypt:encrypt-rule(?)TagEncrypt rule

<sharding:props />

NameTypeDescription
sql.show (?)AttributeShow SQL or not; default value: false
executor.size (?)AttributeExecuting thread number; default value: CPU core number
max.connections.size.per.query (?)AttributeThe maximum connection number that each physical database allocates to each query; default value: 1
check.table.metadata.enabled (?)AttributeWhether to check meta-data consistency of sharding table when it initializes; default value: false
query.with.cipher.column (?)AttributeWhen there is a plainColumn, use cipherColumn or not to query, default value: true

Readwrite-Splitting

Configuration Item Explanation

Namespace: http://shardingsphere.apache.org/schema/shardingsphere/masterslave/master-slave.xsd

<master-slave:data-source />

NameTypeExplanation
idAttributeSpring Bean id
master-data-source-nameAttributeBean id of data source in master database
slave-data-source-namesAttributeBean id list of data source in slave database; multiple Beans are separated by commas
strategy-ref (?)AttributeSlave database load balance algorithm reference; the class needs to implement MasterSlaveLoadBalanceAlgorithm interface
strategy-type (?)AttributeLoad balance algorithm type of slave database; optional value: ROUND_ROBIN and RANDOM; if there is load-balance-algorithm-class-name, the configuration can be omitted
config-map (?)TagUsers’ self-defined configurations
props (?)TagAttribute configurations

<master-slave:props />

NameTypeExplanation
sql.show (?)AttributeShow SQL or not; default value: false
executor.size (?)AttributeExecuting thread number; default value: CPU core number
max.connections.size.per.query (?)AttributeThe maximum connection number that each physical database allocates to each query; default value: 1
check.table.metadata.enabled (?)AttributeWhether to check meta-data consistency of sharding table when it initializes; default value: false

<master-slave:load-balance-algorithm />

4.0.0-RC2 version added

NameTypeExplanation
idAttributeSpring Bean Id
typeAttributeType of load balance algorithm, ‘RANDOM’或’ROUND_ROBIN’, support custom extension
props-ref (?)AttributeProperties of load balance algorithm

Data Masking

Configuration Item Explanation

Namespace: http://shardingsphere.apache.org/schema/shardingsphere/encrypt/encrypt.xsd

<encrypt:data-source />

NameTypeType
idAttributeSpring Bean Id
data-source-nameAttributeEncrypt data source Bean Id
props (?)TagAttribute configurations

<encrypt:encryptors />

NameTypeType
encryptor(+)TagEncryptor configuration

<encrypt:encryptor />

NameTypeType
idAttributeNames of Encryptor
typeAttributeTypes of Encryptor, including MD5/AES or customize type
props-reAttributeAttribute configurations

<encrypt:tables />

NameTypeType
table(+)TagEncrypt table configuration

<encrypt:table />

NameTypeType
column(+)TagEncrypt column configuration

<encrypt:column />

NameTypeDescription
logic-columnAttributeColumn logic name
cipher-columnAttributeCipher column name
assisted-query-column (?)AttributeAssisted query column name
plain-column (?)AttributePlain column name

<encrypt:props />

NameTypeDescription
sql.show (?)AttributeShow SQL or not; default value: false
query.with.cipher.column (?)AttributeWhen there is a plainColumn, use cipherColumn or not to query, default value: true

Orchestration

Data Sharding + Orchestration

Namespace: http://shardingsphere.apache.org/schema/shardingsphere/orchestration/orchestration.xsd

<orchestration:master-slave-data-source />

NameTypeDescription
idAttributeId
data-source-ref (?)AttributeOrchestrated database Id
registry-center-refAttributeRegistry center Id
overwriteAttributeWhether to overwrite local configurations with registry center configurations; if it can, each initialization should refer to local configurations; default means not to overwrite

Read-Write Split + Orchestration

Namespace: http://shardingsphere.apache.org/schema/shardingsphere/orchestration/orchestration.xsd

<orchestration:sharding-data-source />

NameTypeDescription
idAttributeId
data-source-ref (?)AttributeOrchestrated database Id
registry-center-refAttributeRegistry center Id
overwriteAttributeUse local configuration to overwrite registry center or not

Data Masking + Orchestration

Namespace: http://shardingsphere.apache.org/schema/shardingsphere/orchestration/orchestration.xsd

<orchestration:encrypt-data-source />

NameTypeDescription
idAttributeId
data-source-ref (?)AttributeOrchestrated database Id
registry-center-refAttributeRegistry center Id
overwriteAttributeUse local configuration to overwrite registry center or not

Orchestration registry center

Namespace: http://shardingsphere.apache.org/schema/shardingsphere/orchestration/orchestration.xsd

<orchestration:registry-center />

NameTypeDescription
idAttributeSpring Bean Id of registry center
typeAttributeRegistry center type. Example:zookeeper
server-listsAttributeRegistry servers list, multiple split as comma. Example: host1:2181,host2:2181
namespace (?)AttributeNamespace of registry
digest (?)AttributeDigest for registry. Default is not need digest
operation-timeout-milliseconds (?)AttributeOperation timeout time in milliseconds, default value is 500 seconds
max-retries (?)AttributeMax number of times to retry, default value is 3
retry-interval-milliseconds (?)AttributeTime interval in milliseconds on each retry, default value is 500 milliseconds
time-to-live-seconds (?)AttributeLiving time of temporary nodes; default value: 60 seconds
props-ref (?)AttributeOther customize properties of registry center

3.x

Attention Inline expression identifier can use ${...} or $->{...}, but ${...} is conflict with spring placeholder of properties, so use $->{...} on spring environment is better.

Sharding

Configuration Item Explanation

  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:p="http://www.springframework.org/schema/p"
  5. xmlns:context="http://www.springframework.org/schema/context"
  6. xmlns:tx="http://www.springframework.org/schema/tx"
  7. xmlns:sharding="http://shardingsphere.io/schema/shardingsphere/sharding"
  8. xsi:schemaLocation="http://www.springframework.org/schema/beans
  9. http://www.springframework.org/schema/beans/spring-beans.xsd
  10. http://shardingsphere.io/schema/shardingsphere/sharding
  11. http://shardingsphere.io/schema/shardingsphere/sharding/sharding.xsd
  12. http://www.springframework.org/schema/context
  13. http://www.springframework.org/schema/context/spring-context.xsd
  14. http://www.springframework.org/schema/tx
  15. http://www.springframework.org/schema/tx/spring-tx.xsd">
  16. <context:annotation-config />
  17. <context:component-scan base-package="io.shardingsphere.example.spring.namespace.jpa" />
  18. <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
  19. <property name="dataSource" ref="shardingDataSource" />
  20. <property name="jpaVendorAdapter">
  21. <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" p:database="MYSQL" />
  22. </property>
  23. <property name="packagesToScan" value="io.shardingsphere.example.spring.namespace.jpa.entity" />
  24. <property name="jpaProperties">
  25. <props>
  26. <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
  27. <prop key="hibernate.hbm2ddl.auto">create</prop>
  28. <prop key="hibernate.show_sql">true</prop>
  29. </props>
  30. </property>
  31. </bean>
  32. <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" p:entityManagerFactory-ref="entityManagerFactory" />
  33. <tx:annotation-driven />
  34. <bean id="ds0" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  35. <property name="driverClassName" value="com.mysql.jdbc.Driver" />
  36. <property name="url" value="jdbc:mysql://localhost:3306/ds0" />
  37. <property name="username" value="root" />
  38. <property name="password" value="" />
  39. </bean>
  40. <bean id="ds1" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  41. <property name="driverClassName" value="com.mysql.jdbc.Driver" />
  42. <property name="url" value="jdbc:mysql://localhost:3306/ds1" />
  43. <property name="username" value="root" />
  44. <property name="password" value="" />
  45. </bean>
  46. <bean id="preciseModuloDatabaseShardingAlgorithm" class="io.shardingsphere.example.spring.namespace.jpa.algorithm.PreciseModuloDatabaseShardingAlgorithm" />
  47. <bean id="preciseModuloTableShardingAlgorithm" class="io.shardingsphere.example.spring.namespace.jpa.algorithm.PreciseModuloTableShardingAlgorithm" />
  48. <sharding:standard-strategy id="databaseShardingStrategy" sharding-column="user_id" precise-algorithm-ref="preciseModuloDatabaseShardingAlgorithm" />
  49. <sharding:standard-strategy id="tableShardingStrategy" sharding-column="order_id" precise-algorithm-ref="preciseModuloTableShardingAlgorithm" />
  50. <sharding:data-source id="shardingDataSource">
  51. <sharding:sharding-rule data-source-names="ds0,ds1">
  52. <sharding:table-rules>
  53. <sharding:table-rule logic-table="t_order" actual-data-nodes="ds$->{0..1}.t_order$->{0..1}" database-strategy-ref="databaseShardingStrategy" table-strategy-ref="tableShardingStrategy" generate-key-column-name="order_id" />
  54. <sharding:table-rule logic-table="t_order_item" actual-data-nodes="ds$->{0..1}.t_order_item$->{0..1}" database-strategy-ref="databaseShardingStrategy" table-strategy-ref="tableShardingStrategy" generate-key-column-name="order_item_id" />
  55. </sharding:table-rules>
  56. <sharding:binding-table-rules>
  57. <sharding:binding-table-rule logic-tables="t_order, t_order_item" />
  58. </sharding:binding-table-rules>
  59. <sharding:broadcast-table-rules>
  60. <sharding:broadcast-table-rule table="t_config" />
  61. </sharding:broadcast-table-rules>
  62. </sharding:sharding-rule>
  63. </sharding:data-source>
  64. </beans>

Readwrite-splitting

Configuration Item Explanation

  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:context="http://www.springframework.org/schema/context"
  5. xmlns:p="http://www.springframework.org/schema/p"
  6. xmlns:tx="http://www.springframework.org/schema/tx"
  7. xmlns:master-slave="http://shardingsphere.io/schema/shardingsphere/masterslave"
  8. xsi:schemaLocation="http://www.springframework.org/schema/beans
  9. http://www.springframework.org/schema/beans/spring-beans.xsd
  10. http://www.springframework.org/schema/context
  11. http://www.springframework.org/schema/context/spring-context.xsd
  12. http://www.springframework.org/schema/tx
  13. http://www.springframework.org/schema/tx/spring-tx.xsd
  14. http://shardingsphere.io/schema/shardingsphere/masterslave
  15. http://shardingsphere.io/schema/shardingsphere/masterslave/master-slave.xsd">
  16. <context:annotation-config />
  17. <context:component-scan base-package="io.shardingsphere.example.spring.namespace.jpa" />
  18. <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
  19. <property name="dataSource" ref="masterSlaveDataSource" />
  20. <property name="jpaVendorAdapter">
  21. <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" p:database="MYSQL" />
  22. </property>
  23. <property name="packagesToScan" value="io.shardingsphere.example.spring.namespace.jpa.entity" />
  24. <property name="jpaProperties">
  25. <props>
  26. <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
  27. <prop key="hibernate.hbm2ddl.auto">create</prop>
  28. <prop key="hibernate.show_sql">true</prop>
  29. </props>
  30. </property>
  31. </bean>
  32. <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" p:entityManagerFactory-ref="entityManagerFactory" />
  33. <tx:annotation-driven />
  34. <bean id="ds_master" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  35. <property name="driverClassName" value="com.mysql.jdbc.Driver" />
  36. <property name="url" value="jdbc:mysql://localhost:3306/ds_master" />
  37. <property name="username" value="root" />
  38. <property name="password" value="" />
  39. </bean>
  40. <bean id="ds_slave0" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  41. <property name="driverClassName" value="com.mysql.jdbc.Driver" />
  42. <property name="url" value="jdbc:mysql://localhost:3306/ds_slave0" />
  43. <property name="username" value="root" />
  44. <property name="password" value="" />
  45. </bean>
  46. <bean id="ds_slave1" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  47. <property name="driverClassName" value="com.mysql.jdbc.Driver" />
  48. <property name="url" value="jdbc:mysql://localhost:3306/ds_slave1" />
  49. <property name="username" value="root" />
  50. <property name="password" value="" />
  51. </bean>
  52. <bean id="randomStrategy" class="io.shardingsphere.api.algorithm.masterslave.RandomMasterSlaveLoadBalanceAlgorithm" />
  53. <master-slave:data-source id="masterSlaveDataSource" master-data-source-name="ds_master" slave-data-source-names="ds_slave0, ds_slave1" strategy-ref="randomStrategy">
  54. <master-slave:props>
  55. <prop key="sql.show">${sql_show}</prop>
  56. <prop key="executor.size">10</prop>
  57. <prop key="foo">bar</prop>
  58. </master-slave:props>
  59. </master-slave:data-source>
  60. </beans>

Orchestration

Configuration Item Explanation

  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:sharding="http://shardingsphere.io/schema/shardingsphere/orchestration/sharding"
  5. xmlns:master-slave="http://shardingsphere.io/schema/shardingsphere/orchestration/masterslave"
  6. xmlns:reg="http://shardingsphere.io/schema/shardingsphere/orchestration/reg"
  7. xsi:schemaLocation="http://www.springframework.org/schema/beans
  8. http://www.springframework.org/schema/beans/spring-beans.xsd
  9. http://shardingsphere.io/schema/shardingsphere/orchestration/reg
  10. http://shardingsphere.io/schema/shardingsphere/orchestration/reg/reg.xsd
  11. http://shardingsphere.io/schema/shardingsphere/orchestration/sharding
  12. http://shardingsphere.io/schema/shardingsphere/orchestration/sharding/sharding.xsd
  13. http://shardingsphere.io/schema/shardingsphere/orchestration/masterslave
  14. http://shardingsphere.io/schema/shardingsphere/orchestration/masterslave/master-slave.xsd">
  15. <reg:registry-center id="regCenter" server-lists="localhost:2181" namespace="orchestration-spring-namespace-demo" overwtite="false" />
  16. <sharding:data-source id="shardingMasterSlaveDataSource" registry-center-ref="regCenter" />
  17. <master-slave:data-source id="masterSlaveDataSource" registry-center-ref="regCenter" />
  18. </beans>

2.x

Readwrite-splitting

The configuration example for Spring namespace

  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:context="http://www.springframework.org/schema/context"
  5. xmlns:sharding="http://shardingsphere.io/schema/shardingjdbc/sharding"
  6. xmlns:masterslave="http://shardingsphere.io/schema/shardingjdbc/masterslave"
  7. xsi:schemaLocation="http://www.springframework.org/schema/beans
  8. http://www.springframework.org/schema/beans/spring-beans.xsd
  9. http://www.springframework.org/schema/context
  10. http://www.springframework.org/schema/context/spring-context.xsd
  11. http://shardingsphere.io/schema/shardingjdbc/sharding
  12. http://shardingsphere.io/schema/shardingjdbc/sharding/sharding.xsd
  13. http://shardingsphere.io/schema/shardingjdbc/masterslave
  14. http://shardingsphere.io/schema/shardingjdbc/masterslave/master-slave.xsd
  15. ">
  16. <!-- Actual source data Configuration -->
  17. <bean id="dbtbl_0_master" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  18. <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
  19. <property name="url" value="jdbc:mysql://localhost:3306/dbtbl_0_master"/>
  20. <property name="username" value="root"/>
  21. <property name="password" value=""/>
  22. </bean>
  23. <bean id="dbtbl_0_slave_0" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  24. <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
  25. <property name="url" value="jdbc:mysql://localhost:3306/dbtbl_0_slave_0"/>
  26. <property name="username" value="root"/>
  27. <property name="password" value=""/>
  28. </bean>
  29. <bean id="dbtbl_0_slave_1" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  30. <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
  31. <property name="url" value="jdbc:mysql://localhost:3306/dbtbl_0_slave_1"/>
  32. <property name="username" value="root"/>
  33. <property name="password" value=""/>
  34. </bean>
  35. <bean id="dbtbl_1_master" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  36. <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
  37. <property name="url" value="jdbc:mysql://localhost:3306/dbtbl_1_master"/>
  38. <property name="username" value="root"/>
  39. <property name="password" value=""/>
  40. </bean>
  41. <bean id="dbtbl_1_slave_0" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  42. <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
  43. <property name="url" value="jdbc:mysql://localhost:3306/dbtbl_1_slave_0"/>
  44. <property name="username" value="root"/>
  45. <property name="password" value=""/>
  46. </bean>
  47. <bean id="dbtbl_1_slave_1" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  48. <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
  49. <property name="url" value="jdbc:mysql://localhost:3306/dbtbl_1_slave_1"/>
  50. <property name="username" value="root"/>
  51. <property name="password" value=""/>
  52. </bean>
  53. <!-- Readwrite-splitting DataSource Configuration -->
  54. <master-slave:data-source id="dbtbl_0" master-data-source-name="dbtbl_0_master" slave-data-source-names="dbtbl_0_slave_0, dbtbl_0_slave_1" strategy-type="ROUND_ROBIN" />
  55. <master-slave:data-source id="dbtbl_1" master-data-source-name="dbtbl_1_master" slave-data-source-names="dbtbl_1_slave_0, dbtbl_1_slave_1" strategy-type="ROUND_ROBIN" />
  56. <sharding:inline-strategy id="databaseStrategy" sharding-column="user_id" algorithm-expression="dbtbl_${user_id % 2}" />
  57. <sharding:inline-strategy id="orderTableStrategy" sharding-column="order_id" algorithm-expression="t_order_${order_id % 4}" />
  58. <sharding:data-source id="shardingDataSource">
  59. <sharding:sharding-rule data-source-names="dbtbl_0, dbtbl_1">
  60. <sharding:table-rules>
  61. <sharding:table-rule logic-table="t_order" actual-data-nodes="dbtbl_${0..1}.t_order_${0..3}" database-strategy-ref="databaseStrategy" table-strategy-ref="orderTableStrategy"/>
  62. </sharding:table-rules>
  63. </sharding:sharding-rule>
  64. </sharding:data-source>
  65. </beans>