META-INF.sample.datasource-shard.xml Maven / Gradle / Ivy
<?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:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.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"> <bean id="multipleDataSource" class="com.github.dennisit.vplus.data.dsource.multi.MultipleDataSource"> <property name="targetDataSources"> <map key-type="java.lang.String"> <entry key="dbA" value-ref="dbB"/> <entry key="dbB" value-ref="dbB"/> <entry key="dbShard0" value-ref="dbShard0"/> </map> </property> <property name="defaultTargetDataSource" ref="dbA"/> </bean> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="multipleDataSource"/> </bean> <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate"> <constructor-arg ref="sqlSessionFactory"/> </bean> <bean id="multiMybatisTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" p:dataSource-ref="multipleDataSource"/> <tx:advice id="multiMybatisAdvice" transaction-manager="multiMybatisTransactionManager"> <tx:attributes> <tx:method name="save*" propagation="REQUIRED"/> <tx:method name="insert*" propagation="REQUIRED"/> <tx:method name="add*" propagation="REQUIRED"/> <tx:method name="update*" propagation="REQUIRED"/> <tx:method name="delete*" propagation="REQUIRED"/> <tx:method name="remove*" propagation="REQUIRED"/> <tx:method name="accept*" propagation="REQUIRED"/> <tx:method name="reject*" propagation="REQUIRED"/> <tx:method name="execute*" propagation="REQUIRED"/> <tx:method name="del*" propagation="REQUIRED"/> <tx:method name="recover*" propagation="REQUIRED"/> <tx:method name="sync*" propagation="REQUIRED"/> <tx:method name="*" read-only="true"/> </tx:attributes> </tx:advice> <context:component-scan base-package="com.github.dennisit.vplus.data.dsource.shard"/> <!-- 散表配置 --> <bean id="shardMultipleDataSourceAspect" class="com.github.dennisit.vplus.data.dsource.shard.ShardDataSourceAspect"> <property name="shardContext" ref="shardFactory"/> </bean> <aop:config> <aop:aspect ref="shardMultipleDataSourceAspect"> <aop:around method="doAround" pointcut="execution(public * com..wuyu..mapper.*.*(..))"/> </aop:aspect> </aop:config> </beans>