| <?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.io/schema/shardingsphere/sharding" |
| xsi:schemaLocation="http://www.springframework.org/schema/beans |
| http://www.springframework.org/schema/beans/spring-beans.xsd |
| http://www.springframework.org/schema/tx |
| http://www.springframework.org/schema/tx/spring-tx.xsd |
| http://www.springframework.org/schema/context |
| http://www.springframework.org/schema/context/spring-context.xsd |
| http://shardingsphere.io/schema/shardingsphere/sharding |
| http://shardingsphere.io/schema/shardingsphere/sharding/sharding.xsd"> |
| <context:component-scan base-package="io.shardingsphere.example.spring.namespace.mybatis" /> |
| |
| <bean id="demo_ds_0" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> |
| <property name="driverClassName" value="com.mysql.jdbc.Driver"/> |
| <property name="url" value="jdbc:mysql://localhost:3306/demo_ds_0"/> |
| <property name="username" value="root"/> |
| <property name="password" value=""/> |
| </bean> |
| |
| <bean id="demo_ds_1" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> |
| <property name="driverClassName" value="com.mysql.jdbc.Driver"/> |
| <property name="url" value="jdbc:mysql://localhost:3306/demo_ds_1"/> |
| <property name="username" value="root"/> |
| <property name="password" value=""/> |
| </bean> |
| |
| <bean id="preciseModuloDatabaseShardingAlgorithm" class="io.shardingsphere.example.spring.namespace.mybatis.fixtrue.algorithm.PreciseModuloDatabaseShardingAlgorithm" /> |
| <bean id="preciseModuloTableShardingAlgorithm" class="io.shardingsphere.example.spring.namespace.mybatis.fixtrue.algorithm.PreciseModuloTableShardingAlgorithm" /> |
| |
| <sharding:standard-strategy id="databaseShardingStrategy" sharding-column="user_id" precise-algorithm-ref="preciseModuloDatabaseShardingAlgorithm" /> |
| <sharding:standard-strategy id="tableShardingStrategy" sharding-column="order_id" precise-algorithm-ref="preciseModuloTableShardingAlgorithm" /> |
| |
| <sharding:data-source id="shardingDataSource"> |
| <sharding:sharding-rule data-source-names="demo_ds_0, demo_ds_1"> |
| <sharding:table-rules> |
| <sharding:table-rule logic-table="t_order" actual-data-nodes="demo_ds_${0..1}.t_order_${0..1}" database-strategy-ref="databaseShardingStrategy" table-strategy-ref="tableShardingStrategy" generate-key-column-name="order_id" /> |
| <sharding:table-rule logic-table="t_order_item" actual-data-nodes="demo_ds_${0..1}.t_order_item_${0..1}" database-strategy-ref="databaseShardingStrategy" table-strategy-ref="tableShardingStrategy" generate-key-column-name="order_item_id" /> |
| </sharding:table-rules> |
| </sharding:sharding-rule> |
| </sharding:data-source> |
| |
| <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> |
| <property name="dataSource" ref="shardingDataSource" /> |
| </bean> |
| <tx:annotation-driven /> |
| |
| <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> |
| <property name="dataSource" ref="shardingDataSource"/> |
| <property name="mapperLocations" value="classpath*:META-INF/mappers/*.xml"/> |
| </bean> |
| |
| <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> |
| <property name="basePackage" value="io.shardingsphere.example.spring.namespace.mybatis"/> |
| <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/> |
| </bean> |
| </beans> |