数据库表散列web.xml 配置

来源:互联网 发布:saas企业级软件服务 编辑:程序博客网 时间:2024/06/05 00:39

数据库表散列

<!-- 使用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>

1.0配置数据源 并且对多个数据源进行分组

<!-- 配置数据源开始 --><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="partition1"/>       <!--                       主数据库 -->                <property name="targetDataSource" ref="dataSource1"/>                <property name="targetDetectorDataSource" ref="dataSource1"/>        <!--                    从数据库 -->                <property name="standbyDataSource" ref="dataSource4"/>                <property name="standbyDetectorDataSource" ref="dataSource4"/>            </bean>            <bean class="com.caland.sun.client.datasources.DataSourceDescriptor">                <property name="identity" value="partition2"/>                <property name="targetDataSource" ref="dataSource2"/>                <property name="targetDetectorDataSource" ref="dataSource2"/>                <property name="standbyDataSource" ref="dataSource5"/>                <property name="standbyDetectorDataSource" ref="dataSource5"/>            </bean>            <bean class="com.caland.sun.client.datasources.DataSourceDescriptor">                <property name="identity" value="partition3"/>                <property name="targetDataSource" ref="dataSource3"/>                <property name="targetDetectorDataSource" ref="dataSource3"/>                <property name="standbyDataSource" ref="dataSource6"/>                <property name="standbyDetectorDataSource" ref="dataSource6"/>            </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><!-- 数据源1 --><bean id="dataSource1" 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="dataSource2" 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="dataSource3" 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="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="dataSource4" 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="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="dataSource5" 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="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="dataSource6" 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"/>









2.0-路由规则配置




3.0-事物配置

<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="dataSource1" />      <property name="configLocation">        <value>classpath:/sqlmap-config.xml</value>    </property></bean>

4.0-配置工程所需要的模板

注意: 这里使用的是Freemarker(通常用作页面的静态化),可以根据模板进行替换

<!-- 工程里一定要使用此工程模板,不能再使用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>


参考的文章
http://blog.csdn.net/sd4422739/article/details/49514981
https://github.com/v5uncode/uncode-framework-parent

0 0
原创粉丝点击