| <?xml version="1.0" encoding="UTF-8"?> |
| <beans xmlns="http://www.springframework.org/schema/beans" |
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| xmlns:context="http://www.springframework.org/schema/context" |
| xmlns:tx="http://www.springframework.org/schema/tx" |
| xmlns:sharding="http://shardingsphere.apache.org/schema/shardingsphere/sharding" |
| xmlns:reg="http://shardingsphere.apache.org/schema/shardingsphere/orchestration" |
| xmlns:master-slave="http://shardingsphere.apache.org/schema/shardingsphere/masterslave" |
| xmlns:bean="http://www.springframework.org/schema/util" |
| xsi:schemaLocation="http://www.springframework.org/schema/beans |
| http://www.springframework.org/schema/beans/spring-beans.xsd |
| http://www.springframework.org/schema/context |
| http://www.springframework.org/schema/context/spring-context.xsd |
| http://www.springframework.org/schema/tx |
| http://www.springframework.org/schema/tx/spring-tx.xsd |
| http://shardingsphere.apache.org/schema/shardingsphere/sharding |
| http://shardingsphere.apache.org/schema/shardingsphere/sharding/sharding.xsd |
| http://shardingsphere.apache.org/schema/shardingsphere/masterslave |
| http://shardingsphere.apache.org/schema/shardingsphere/masterslave/master-slave.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd |
| http://shardingsphere.apache.org/schema/shardingsphere/orchestration |
| http://shardingsphere.apache.org/schema/shardingsphere/orchestration/orchestration.xsd"> |
| <context:component-scan base-package="org.apache.shardingsphere.example.core.mybatis" /> |
| |
| <bean id="demo_ds_master_0" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close"> |
| <property name="driverClassName" value="org.postgresql.Driver"/> |
| <property name="jdbcUrl" value="jdbc:postgresql://localhost:5432/shardingsphere?currentSchema=demo_ds_master_0"/> |
| <property name="username" value="postgres"/> |
| <property name="password" value=""/> |
| </bean> |
| |
| <bean id="demo_ds_master_0_slave_0" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close"> |
| <property name="driverClassName" value="org.postgresql.Driver"/> |
| <property name="jdbcUrl" value="jdbc:postgresql://localhost:5432/shardingsphere?currentSchema=demo_ds_master_0_slave_0"/> |
| <property name="username" value="postgres"/> |
| <property name="password" value=""/> |
| </bean> |
| |
| <bean id="demo_ds_master_0_slave_1" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close"> |
| <property name="driverClassName" value="org.postgresql.Driver"/> |
| <property name="jdbcUrl" value="jdbc:postgresql://localhost:5432/shardingsphere?currentSchema=demo_ds_master_0_slave_1"/> |
| <property name="username" value="postgres"/> |
| <property name="password" value=""/> |
| </bean> |
| |
| <bean id="demo_ds_master_1" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close"> |
| <property name="driverClassName" value="org.postgresql.Driver"/> |
| <property name="jdbcUrl" value="jdbc:postgresql://localhost:5432/shardingsphere?currentSchema=demo_ds_master_1"/> |
| <property name="username" value="postgres"/> |
| <property name="password" value=""/> |
| </bean> |
| |
| <bean id="demo_ds_master_1_slave_0" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close"> |
| <property name="driverClassName" value="org.postgresql.Driver"/> |
| <property name="jdbcUrl" value="jdbc:postgresql://localhost:5432/shardingsphere?currentSchema=demo_ds_master_1_slave_0"/> |
| <property name="username" value="postgres"/> |
| <property name="password" value=""/> |
| </bean> |
| |
| <bean id="demo_ds_master_1_slave_1" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close"> |
| <property name="driverClassName" value="org.postgresql.Driver"/> |
| <property name="jdbcUrl" value="jdbc:postgresql://localhost:5432/shardingsphere?currentSchema=demo_ds_master_1_slave_1"/> |
| <property name="username" value="postgres"/> |
| <property name="password" value=""/> |
| </bean> |
| |
| <sharding:inline-strategy id="databaseStrategy" sharding-column="user_id" algorithm-expression="demo_ds_ms_${user_id % 2}" /> |
| <sharding:inline-strategy id="orderTableStrategy" sharding-column="order_id" algorithm-expression="t_order_${order_id % 2}" /> |
| <sharding:inline-strategy id="orderItemTableStrategy" sharding-column="order_item_id" algorithm-expression="t_order_item_${order_item_id % 2}" /> |
| |
| <bean:properties id="properties"> |
| <prop key="worker.id">123</prop> |
| </bean:properties> |
| |
| <sharding:key-generator id="orderKeyGenerator" type="SNOWFLAKE" column="order_id" props-ref="properties" /> |
| <sharding:key-generator id="itemKeyGenerator" type="SNOWFLAKE" column="order_item_id" props-ref="properties" /> |
| |
| <master-slave:load-balance-algorithm id="randomStrategy" type="RANDOM" /> |
| |
| <sharding:data-source id="shardingDataSource"> |
| <sharding:sharding-rule data-source-names="demo_ds_master_0,demo_ds_master_0_slave_0,demo_ds_master_0_slave_1,demo_ds_master_1,demo_ds_master_1_slave_0,demo_ds_master_1_slave_1"> |
| <sharding:master-slave-rules> |
| <sharding:master-slave-rule id="demo_ds_ms_0" master-data-source-name="demo_ds_master_0" slave-data-source-names="demo_ds_master_0_slave_0, demo_ds_master_0_slave_1" strategy-ref="randomStrategy" /> |
| <sharding:master-slave-rule id="demo_ds_ms_1" master-data-source-name="demo_ds_master_1" slave-data-source-names="demo_ds_master_1_slave_0, demo_ds_master_1_slave_1" strategy-ref="randomStrategy" /> |
| </sharding:master-slave-rules> |
| <sharding:table-rules> |
| <sharding:table-rule logic-table="t_order" actual-data-nodes="demo_ds_ms_${0..1}.t_order_${0..1}" database-strategy-ref="databaseStrategy" table-strategy-ref="orderTableStrategy" key-generator-ref="orderKeyGenerator"/> |
| <sharding:table-rule logic-table="t_order_item" actual-data-nodes="demo_ds_ms_${0..1}.t_order_item_${0..1}" database-strategy-ref="databaseStrategy" table-strategy-ref="orderItemTableStrategy" key-generator-ref="itemKeyGenerator"/> |
| </sharding:table-rules> |
| <sharding:binding-table-rules> |
| <sharding:binding-table-rule logic-tables="t_order,t_order_item"/> |
| </sharding:binding-table-rules> |
| <sharding:broadcast-table-rules> |
| <sharding:broadcast-table-rule table="t_address"/> |
| </sharding:broadcast-table-rules> |
| </sharding:sharding-rule> |
| <sharding:props> |
| <prop key="sql.show">false</prop> |
| </sharding:props> |
| </sharding:data-source> |
| |
| <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> |
| <property name="dataSource" ref="shardingDataSource" /> |
| </bean> |
| <tx:annotation-driven /> |
| <reg:sharding-data-source id="orchestration-spring-namespace-postgresql-sharding-MS" registry-center-ref="myRegistry" data-source-ref="shardingDataSource" overwrite="true"/> |
| |
| <reg:registry-center id="myRegistry" type="zookeeper" server-lists="localhost:2181" namespace="orchestration-spring-namespace-postgresql" /> |
| |
| <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> |
| <property name="dataSource" ref="shardingDataSource"/> |
| <property name="mapperLocations" value="classpath*:META-INF/mappers/postgresql/*.xml"/> |
| </bean> |
| |
| <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> |
| <property name="basePackage" value="org.apache.shardingsphere.example.core.mybatis.repository"/> |
| <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/> |
| </bean> |
| </beans> |