mysql多路由

35 篇文章 0 订阅
<?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:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
	http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
	http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"
	default-lazy-init="true">

	<!-- 使用Annotation自动注册Bean,解决事物失效问题:在主容器中不扫描@Controller注解,在SpringMvc中只扫描@Controller注解。 -->
	<context:component-scan base-package="com"><!-- base-package 如果多个,用“,”分隔 -->
		<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
	</context:component-scan>

	<context:annotation-config />
	<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="location">
			<value>classpath:/jdbc.properties</value>
		</property>
	</bean>

	<!-- 配置数据源开始 -->
	<bean id="dataSources" class="com.caland.sun.client.datasources.DefaultDataSourceService">
		<property name="dataSourceDescriptors">
			<set>
				<bean class="com.caland.sun.client.datasources.DataSourceDescriptor">
					<property name="identity" value="partitionLocal" />
					<property name="targetDataSource" ref="dataSourceLocal" />
					<property name="targetDetectorDataSource" ref="dataSourceLocal" />
					<property name="standbyDataSource" ref="dataSourceLocal" />
					<property name="standbyDetectorDataSource" ref="dataSourceLocal" />
				</bean>
				<bean class="com.caland.sun.client.datasources.DataSourceDescriptor">
					<property name="identity" value="partition2016" />
					<property name="targetDataSource" ref="dataSource2016" />
					<property name="targetDetectorDataSource" ref="dataSource2016" />
					<property name="standbyDataSource" ref="dataSource2016" />
					<property name="standbyDetectorDataSource" ref="dataSource2016" />
				</bean>
				<bean class="com.caland.sun.client.datasources.DataSourceDescriptor">
					<property name="identity" value="partition2017" />
					<property name="targetDataSource" ref="dataSource2017" />
					<property name="targetDetectorDataSource" ref="dataSource2017" />
					<property name="standbyDataSource" ref="dataSource2017" />
					<property name="standbyDetectorDataSource" ref="dataSource2017" />
				</bean>
				<bean class="com.caland.sun.client.datasources.DataSourceDescriptor">
					<property name="identity" value="partition2018" />
					<property name="targetDataSource" ref="dataSource2018" />
					<property name="targetDetectorDataSource" ref="dataSource2018" />
					<property name="standbyDataSource" ref="dataSource2018" />
					<property name="standbyDetectorDataSource" ref="dataSource2018" />
				</bean>
				<bean class="com.caland.sun.client.datasources.DataSourceDescriptor">
					<property name="identity" value="partition2019" />
					<property name="targetDataSource" ref="dataSource2019" />
					<property name="targetDetectorDataSource" ref="dataSource2019" />
					<property name="standbyDataSource" ref="dataSource2019" />
					<property name="standbyDetectorDataSource" ref="dataSource2019" />
				</bean>
				<bean class="com.caland.sun.client.datasources.DataSourceDescriptor">
					<property name="identity" value="partition2020" />
					<property name="targetDataSource" ref="dataSource2020" />
					<property name="targetDetectorDataSource" ref="dataSource2020" />
					<property name="standbyDataSource" ref="dataSource2020" />
					<property name="standbyDetectorDataSource" ref="dataSource2020" />
				</bean>
				<bean class="com.caland.sun.client.datasources.DataSourceDescriptor">
					<property name="identity" value="partition2021" />
					<property name="targetDataSource" ref="dataSource2021" />
					<property name="targetDetectorDataSource" ref="dataSource2021" />
					<property name="standbyDataSource" ref="dataSource2021" />
					<property name="standbyDetectorDataSource" ref="dataSource2021" />
				</bean>
				<bean class="com.caland.sun.client.datasources.DataSourceDescriptor">
					<property name="identity" value="partition2022" />
					<property name="targetDataSource" ref="dataSource2022" />
					<property name="targetDetectorDataSource" ref="dataSource2022" />
					<property name="standbyDataSource" ref="dataSource2022" />
					<property name="standbyDetectorDataSource" ref="dataSource2022" />
				</bean>
			</set>
		</property>
		<property name="haDataSourceCreator">
			<bean class="com.caland.sun.client.datasources.ha.FailoverHotSwapDataSourceCreator">
				<property name="detectingSql" value="update caland set timeflag=CURRENT_TIMESTAMP()" />
			</bean>
		</property>
	</bean>

	<!-- 本地数据源 -->
	<bean id="dataSourceLocal" class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="driverClass" value="${jdbc.driverClassName}" />
		<property name="jdbcUrl" value="${jdbc0.url}" />
		<property name="user" value="${jdbc0.username}" />
		<property name="password" value="${jdbc0.password}" />
		<property name="autoCommitOnClose" value="true" />
		<!-- <property name="checkoutTimeout" value="${cpool.checkoutTimeout}"/> -->
		<property name="initialPoolSize" value="${cpool.minPoolSize}" />
		<property name="minPoolSize" value="${cpool.minPoolSize}" />
		<property name="maxPoolSize" value="${cpool.maxPoolSize}" />
		<property name="maxIdleTime" value="${cpool.maxIdleTime}" />
		<property name="acquireIncrement" value="${cpool.acquireIncrement}" />
		<property name="maxIdleTimeExcessConnections" value="${cpool.maxIdleTimeExcessConnections}" />
	</bean>
	
	<!-- 数据源1 -->
	<bean id="dataSource2016" class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="driverClass" value="${jdbc.driverClassName}" />
		<property name="jdbcUrl" value="${jdbc1.url}" />
		<property name="user" value="${jdbc1.username}" />
		<property name="password" value="${jdbc1.password}" />
		<property name="autoCommitOnClose" value="true" />
		<!-- <property name="checkoutTimeout" value="${cpool.checkoutTimeout}"/> -->
		<property name="initialPoolSize" value="${cpool.minPoolSize}" />
		<property name="minPoolSize" value="${cpool.minPoolSize}" />
		<property name="maxPoolSize" value="${cpool.maxPoolSize}" />
		<property name="maxIdleTime" value="${cpool.maxIdleTime}" />
		<property name="acquireIncrement" value="${cpool.acquireIncrement}" />
		<property name="maxIdleTimeExcessConnections" value="${cpool.maxIdleTimeExcessConnections}" />
	</bean>

	<!-- 数据源2 -->
	<bean id="dataSource2017" class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="driverClass" value="${jdbc.driverClassName}" />
		<property name="jdbcUrl" value="${jdbc2.url}" />
		<property name="user" value="${jdbc2.username}" />
		<property name="password" value="${jdbc2.password}" />
		<property name="autoCommitOnClose" value="true" />
		<!-- <property name="checkoutTimeout" value="${cpool.checkoutTimeout}"/> -->
		<property name="initialPoolSize" value="${cpool.minPoolSize}" />
		<property name="minPoolSize" value="${cpool.minPoolSize}" />
		<property name="maxPoolSize" value="${cpool.maxPoolSize}" />
		<property name="maxIdleTime" value="${cpool.maxIdleTime}" />
		<property name="acquireIncrement" value="${cpool.acquireIncrement}" />
		<property name="maxIdleTimeExcessConnections" value="${cpool.maxIdleTimeExcessConnections}" />
	</bean>

	<!-- 数据源3 -->
	<bean id="dataSource2018" class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="driverClass" value="${jdbc.driverClassName}" />
		<property name="jdbcUrl" value="${jdbc3.url}" />
		<property name="user" value="${jdbc3.username}" />
		<property name="password" value="${jdbc3.password}" />
		<property name="autoCommitOnClose" value="true" />
		<!-- <property name="checkoutTimeout" value="${cpool.checkoutTimeout}"/> -->
		<property name="initialPoolSize" value="${cpool.minPoolSize}" />
		<property name="minPoolSize" value="${cpool.minPoolSize}" />
		<property name="maxPoolSize" value="${cpool.maxPoolSize}" />
		<property name="maxIdleTime" value="${cpool.maxIdleTime}" />
		<property name="acquireIncrement" value="${cpool.acquireIncrement}" />
		<property name="maxIdleTimeExcessConnections" value="${cpool.maxIdleTimeExcessConnections}" />
	</bean>
	<!-- 数据源4 -->
	<bean id="dataSource2019" class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="driverClass" value="${jdbc.driverClassName}" />
		<property name="jdbcUrl" value="${jdbc4.url}" />
		<property name="user" value="${jdbc4.username}" />
		<property name="password" value="${jdbc4.password}" />
		<property name="autoCommitOnClose" value="true" />
		<!-- <property name="checkoutTimeout" value="${cpool.checkoutTimeout}"/> -->
		<property name="initialPoolSize" value="${cpool.minPoolSize}" />
		<property name="minPoolSize" value="${cpool.minPoolSize}" />
		<property name="maxPoolSize" value="${cpool.maxPoolSize}" />
		<property name="maxIdleTime" value="${cpool.maxIdleTime}" />
		<property name="acquireIncrement" value="${cpool.acquireIncrement}" />
		<property name="maxIdleTimeExcessConnections" value="${cpool.maxIdleTimeExcessConnections}" />
	</bean>
	<!-- 数据源5 -->
	<bean id="dataSource2020" class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="driverClass" value="${jdbc.driverClassName}" />
		<property name="jdbcUrl" value="${jdbc5.url}" />
		<property name="user" value="${jdbc5.username}" />
		<property name="password" value="${jdbc5.password}" />
		<property name="autoCommitOnClose" value="true" />
		<!-- <property name="checkoutTimeout" value="${cpool.checkoutTimeout}"/> -->
		<property name="initialPoolSize" value="${cpool.minPoolSize}" />
		<property name="minPoolSize" value="${cpool.minPoolSize}" />
		<property name="maxPoolSize" value="${cpool.maxPoolSize}" />
		<property name="maxIdleTime" value="${cpool.maxIdleTime}" />
		<property name="acquireIncrement" value="${cpool.acquireIncrement}" />
		<property name="maxIdleTimeExcessConnections" value="${cpool.maxIdleTimeExcessConnections}" />
	</bean>
	<!-- 数据源6 -->
	<bean id="dataSource2021" class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="driverClass" value="${jdbc.driverClassName}" />
		<property name="jdbcUrl" value="${jdbc6.url}" />
		<property name="user" value="${jdbc6.username}" />
		<property name="password" value="${jdbc6.password}" />
		<property name="autoCommitOnClose" value="true" />
		<!-- <property name="checkoutTimeout" value="${cpool.checkoutTimeout}"/> -->
		<property name="initialPoolSize" value="${cpool.minPoolSize}" />
		<property name="minPoolSize" value="${cpool.minPoolSize}" />
		<property name="maxPoolSize" value="${cpool.maxPoolSize}" />
		<property name="maxIdleTime" value="${cpool.maxIdleTime}" />
		<property name="acquireIncrement" value="${cpool.acquireIncrement}" />
		<property name="maxIdleTimeExcessConnections" value="${cpool.maxIdleTimeExcessConnections}" />
	</bean>
	<!-- 数据源7 -->
	<bean id="dataSource2022" class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="driverClass" value="${jdbc.driverClassName}" />
		<property name="jdbcUrl" value="${jdbc7.url}" />
		<property name="user" value="${jdbc7.username}" />
		<property name="password" value="${jdbc7.password}" />
		<property name="autoCommitOnClose" value="true" />
		<!-- <property name="checkoutTimeout" value="${cpool.checkoutTimeout}"/> -->
		<property name="initialPoolSize" value="${cpool.minPoolSize}" />
		<property name="minPoolSize" value="${cpool.minPoolSize}" />
		<property name="maxPoolSize" value="${cpool.maxPoolSize}" />
		<property name="maxIdleTime" value="${cpool.maxIdleTime}" />
		<property name="acquireIncrement" value="${cpool.acquireIncrement}" />
		<property name="maxIdleTimeExcessConnections" value="${cpool.maxIdleTimeExcessConnections}" />
	</bean>
	<!-- 配置数据源结束 -->

	<!-- 配置路由规则开始 -->
	<bean id="hashFunction" class="com.jiumai.carnet.mdb.core.dao.router.HashFunction" />
	<bean id="internalRouter" class="com.caland.sun.client.router.config.InteralRouterXmlFactoryBean">
		<!-- functionsMap是在使用自定义路由规则函数的时候使用 -->
		<property name="functionsMap">
			<map>
				<entry key="hash" value-ref="hashFunction"></entry>
			</map>
		</property>
		<property name="configLocations">
			<list>
				<value>classpath:/dbRule/sharding-rules-on-namespace.xml</value>
			</list>
		</property>
	</bean>
	<!-- 配置路由规则结束 -->

	<!-- 事务配置 -->
	<bean id="transactionManager" class="com.caland.sun.client.transaction.MultipleDataSourcesTransactionManager">
		<property name="dataSourceService" ref="dataSources" />
		<property name="transactionSynchronization" value="2" />
	</bean>

	<!-- 使用annotation定义事务 -->
	<tx:annotation-driven transaction-manager="transactionManager" />

	<!-- iBatis SQL map定义。 -->
	<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
		<!-- 这里配置的dataSource0为默认的数据源,如果找不到数据库的话则到该数据源中查找 -->
		<property name="dataSource" ref="dataSource2017" />
		<property name="configLocation">
			<value>classpath:/sqlmap-config.xml</value>
		</property>
	</bean>

	<!-- 工程里一定要使用此工程模板,不能再使用ibatis原生的api,不然有的情况会不经过的过滤 -->
	<bean id="sqlMapClientTemplate" class="com.caland.sun.client.SunSqlMapClientTemplate">
		<property name="sqlMapClient" ref="sqlMapClient" />
		<property name="dataSourceService" ref="dataSources" />
		<property name="router" ref="internalRouter" />
		<property name="sqlAuditor">
			<bean class="com.caland.sun.client.audit.SimpleSqlAuditor" />
		</property>
		<property name="profileLongTimeRunningSql" value="true" />
		<property name="longTimeRunningSqlIntervalThreshold" value="3600000" />
	</bean>
	
	<import resource="classpath*:spring-quartz.xml" />
</beans>

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值