blob: 640509f0729e6fd45f27496641fb895fa7aaf556 [file] [log] [blame]
<?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:reg="http://shardingsphere.apache.org/schema/shardingsphere/orchestration"
xmlns:sharding="http://shardingsphere.apache.org/schema/shardingsphere/sharding"
xmlns:master-slave="http://shardingsphere.apache.org/schema/shardingsphere/masterslave"
xmlns:bean="http://www.springframework.org/schema/util"
xmlns:encrypt="http://shardingsphere.apache.org/schema/shardingsphere/encrypt"
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/encrypt http://shardingsphere.apache.org/schema/shardingsphere/encrypt/encrypt.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="com.mysql.jdbc.Driver"/>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/demo_ds_master_0?useSSL=false&amp;useUnicode=true&amp;characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<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="com.mysql.jdbc.Driver"/>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/demo_ds_master_0_slave_0?useSSL=false&amp;useUnicode=true&amp;characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<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="com.mysql.jdbc.Driver"/>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/demo_ds_master_0_slave_1?useSSL=false&amp;useUnicode=true&amp;characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<property name="password" value=""/>
</bean>
<bean id="demo_ds_master_1" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/demo_ds_master_1?useSSL=false&amp;useUnicode=true&amp;characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<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="com.mysql.jdbc.Driver"/>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/demo_ds_master_1_slave_0?useSSL=false&amp;useUnicode=true&amp;characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<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="com.mysql.jdbc.Driver"/>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/demo_ds_master_1_slave_1?useSSL=false&amp;useUnicode=true&amp;characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<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="tableStrategy" sharding-column="user_id" algorithm-expression="t_user_${user_id % 2}" />
<bean:properties id="properties">
<prop key="worker.id">123</prop>
</bean: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:encrypt-rule>
<encrypt:tables>
<encrypt:table name="t_user">
<encrypt:column logic-column="user_name" plain-column="user_name" cipher-column="user_name_cipher" encryptor-ref="encryptor_aes" />
<encrypt:column logic-column="pwd" plain-column="pwd_plain" cipher-column="pwd_cipher" encryptor-ref="encryptor_md5"/>
</encrypt:table>
</encrypt:tables>
<encrypt:encryptors>
<encrypt:encryptor id="encryptor_aes" type="AES" props-ref="props"/>
<encrypt:encryptor id="encryptor_md5" type="MD5" />
</encrypt:encryptors>
</sharding:encrypt-rule>
<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_user"
actual-data-nodes="demo_ds_ms_${0..1}.t_user_${0..1}"
database-strategy-ref="databaseStrategy"
table-strategy-ref="tableStrategy" />
</sharding:table-rules>
</sharding:sharding-rule>
<sharding:props>
<prop key="sql.show">false</prop>
</sharding:props>
</sharding:data-source>
<bean:properties id="props">
<prop key="aes.key.value">123456</prop>
</bean:properties>
<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-mysql-sharding-MS-encrypt" 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-mysql" />
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="shardingDataSource"/>
<property name="mapperLocations" value="classpath*:META-INF/mappers/mysql/*.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>