<?xml version="1.0" encoding="UTF-8"?>
<!-- Repository and Service layers -->
<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:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd">

<!-- ========================= Repository RESOURCE DEFINITIONS ========================= -->
    <bean id="slave" class="org.apache.tomcat.jdbc.pool.DataSource">
        <property name="driverClassName" value="${jdbc.mysql.Driver}"/>
        <property name="url" value="${slave.connection}"/>
        <property name="username" value="${slave.username}"/>
        <property name="password" value="${slave.password}"/>
        <!--公共配置属性 -->
        <property name="maxActive" value="100"/>
        <property name="initialSize" value="10"/>
        <property name="minIdle" value="10"/>
        <property name="jdbcInterceptors" value="${tomcat.jdbc.pool.jdbcInterceptors}"/>
        <property name="testWhileIdle" value="true"/>
        <property name="testOnBorrow" value="true"/>
        <property name="validationQuery" value="select 1"/>
        <property name="testOnReturn" value="false"/>
        <property name="validationInterval" value="30000"/>
        <property name="timeBetweenEvictionRunsMillis" value="5000"/>
        <property name="maxWait" value="15000"/>
        <property name="removeAbandoned" value="true"/>
        <property name="removeAbandonedTimeout" value="60"/>
        <property name="logAbandoned" value="false"/>
        <property name="minEvictableIdleTimeMillis" value="30"/>
    </bean>

<bean id="master" class="org.apache.tomcat.jdbc.pool.DataSource">
        <property name="driverClassName" value="${jdbc.mysql.Driver}"/>
        <property name="url" value="${master.connection}"/>
        <property name="username" value="${master.username}"/>
        <property name="password" value="${master.password}"/>
        <!--公共配置属性 -->
        <property name="maxActive" value="100"/>
        <property name="initialSize" value="10"/>
        <property name="minIdle" value="10"/>
        <property name="jdbcInterceptors" value="${tomcat.jdbc.pool.jdbcInterceptors}"/>
        <property name="testWhileIdle" value="true"/>
        <property name="testOnBorrow" value="true"/>
        <property name="validationQuery" value="select 1"/>
        <property name="testOnReturn" value="false"/>
        <property name="validationInterval" value="30000"/>
        <property name="timeBetweenEvictionRunsMillis" value="5000"/>
        <property name="maxWait" value="15000"/>
        <property name="removeAbandoned" value="true"/>
        <property name="removeAbandonedTimeout" value="60"/>
        <property name="logAbandoned" value="false"/>
        <property name="minEvictableIdleTimeMillis" value="30"/>
    </bean>

<bean id="oldmemberdb" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="${oldmemberdb.connection}"/>
        <property name="username" value="${oldmemberdb.username}" />
        <property name="password" value="${oldmemberdb.password}" />
    </bean>

<bean id="dataSource" class="db.DynamicDataSource">
        <property name="master" ref="master"/>
        <property name="slaves">
            <list>
                <ref bean="slave"/>
            </list>
        </property>
    </bean>

<!-- ibatis3 工厂类 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="configLocation" value="classpath:sqlMapConfig.xml"/>
        <property name="mapperLocations"
                  value="classpath:/jdbc/uc/dao/*.xml"/>
        <property name="typeAliasesPackage" value="uc.jdbc.uc.po"/>
    </bean>

<bean id="sqlSessionFactory_1" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="oldmemberdb"/>
        <property name="configLocation" value="classpath:sqlMapConfig.xml"/>
        <property name="mapperLocations"
                  value="classpath:/uc/jdbc/uc/dao/TestMapper.xml"/>
        <property name="typeAliasesPackage" value="uc.jdbc.uc.po"/>
    </bean>

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="uc.jdbc.uc.olddao"/>
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory_1"></property>
    </bean>

<bean class="MapperScannerConfigurer">
        <property name="basePackage" value="uc.jdbc.uc.dao"/>
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
    </bean>

<!-- 定义单个jdbc数据源的事务管理器 -->
    <bean id="transactionManager"
          class="DynamicDataSourceTransactionManager">
        <!-- class="org.springframework.jdbc.datasource.DataSourceTransactionManager">   -->
        <property name="dataSource" ref="dataSource"/>
    </bean>
    <!-- 以 @Transactional 标注来定义事务 -->
    <tx:annotation-driven transaction-manager="trasactionManager"
                          proxy-target-class="true"/>

<bean id="transactionTemplate"
          class="org.springframework.transaction.support.TransactionTemplate">
        <property name="transactionManager" ref="transactionManager"/>
        <!--ISOLATION_DEFAULT 表示由使用的数据库决定  -->
        <property name="isolationLevelName" value="ISOLATION_DEFAULT"/>
        <property name="propagationBehaviorName" value="PROPAGATION_REQUIRED"/>
        <property name="timeout" value="300"/>
    </bean>

<bean id="transactionTemplateNew"
          class="org.springframework.transaction.support.TransactionTemplate">
        <property name="transactionManager" ref="transactionManager"/>
        <!--ISOLATION_DEFAULT 表示由使用的数据库决定  -->
        <property name="isolationLevelName" value="ISOLATION_DEFAULT"/>
        <property name="propagationBehaviorName" value="PROPAGATION_REQUIRES_NEW"/>
        <property name="timeout" value="300"/>
    </bean>

</beans>

spring 配置多个数据源的文件的更多相关文章

  1. Spring配置多个数据源

    Spring 配置多数据源实现数据库读写分离 博客分类: Spring 数据库   现在大型的电子商务系统,在数据库层面大都采用读写分离技术,就是一个Master数据库,多个Slave数据库.Mast ...

  2. Spring配置扫描mybatis的mapper文件注意:

    一般会将不业务的mapper文件放到不同的包中: spring配置扫描就需要配置下面的方式(两个*): <!-- mybatis文件配置,扫描所有mapper文件 --> <bean ...

  3. Spring 配置多个数据源,并实现动态切换

    1.配置两个不同的数据源,如下 <!-- 数据源配置1 --> <bean id="testDataSource1" class="com.alibab ...

  4. SSH框架系列:Spring配置多个数据源

    分类: [java]2013-12-09 16:59 1247人阅读 评论(0) 收藏 举报 1.问题的引入 对于普通的SSH框架而言,一般配置一个数据源,一个SessionFactory,一个事务管 ...

  5. Spring配置,JDBC数据源及事务

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  6. Spring配置多个数据源,并实现数据源的动态切换转载)

    1.首先在config.properties文件中配置两个数据库连接的基本数据.这个省略了 2.在spring配置文件中配置这两个数据源: 数据源1 <!-- initialSize初始化时建立 ...

  7. 使用Spring配置数据源JdbcTemplate

    c3p0作为演示 1.编写资源文件(db.properties) jdbc.user=root jdbc.password=root jdbc.jdbcUrl=jdbc:mysql://localho ...

  8. Spring配置连接池

    ---------------------siwuxie095                                 Spring 配置连接池         1.Spring 配置内置连接 ...

  9. Spring配置数据源

    Spring在第三方依赖包中包含了两个数据源的实现类包,其一是Apache的DBCP,其二是 C3P0.可以在Spring配置文件中利用这两者中任何一个配置数据源. DBCP数据源 DBCP类包位于 ...

随机推荐

  1. 【关于新版Cocos2dx/Cocos2d-JS】安装包和使用方式的变化

    最近有读者反馈说,最新的Cocos2dx或者说2d-JS下载之后跟书本说的安装方式相差很大. 刚下载最新版3.9试了一下,其实用法还是没有变的. 新版把cocos2dx和cocos2d-js合并了,这 ...

  2. Leetcode 303 Range Sum Query - Immutable

    题意:查询一个数组在(i,j]范围内的元素的和. 思路非常简单,做个预处理,打个表就好 拓展:可以使用树状数组来完成该统计,算法复杂度为(logn),该数据结构强力的地方是实现简单,而且能完成实时更新 ...

  3. Leetcode 119 Pascal's Triangle II 数论递推

    杨辉三角,这次要输出第rowIndex行 用滚动数组t进行递推 t[(i+1)%2][j] = t[i%2][j] + t[i%2][j - 1]; class Solution { public: ...

  4. 解决中64位Win7系统上PLSQL无法连接ORACLE的方法(PLSQL无法识别ORACLE_HOME的配置)

    最近新安装了64位的Win7系统,工作中需要用oracle数据库,而数据库是公司IT的DBA进行管理和维护的. 我们只需要连接上去进行使用就可以了,于是我就在自己的机器上安装了oracle clien ...

  5. 只写104行代码!在nopCommerce中如何实现自动生成网站地图

    表告诉我说你不知道nopCommerce是什么.它是目前.NET中最流行的完全开源网上商城,由俄罗斯的团队在2008年开始立项一直开发到现在已经是3.3版本了.代码目前托管在codeplex上,有兴趣 ...

  6. nginx内置全局变量及含义

    名称        版本        说明(变量列表来源于文件 ngx_http_variables ) $args        1.0.8        请求中的参数; $binary_remo ...

  7. nginx+tomcat+java部署总结

    昨天部署了一下nginx+tomcat+java出现了很多问题,以下为整理总结. 使用了两种部署方式,一种是源码部署,一种是war部署. java源码部署总结: 环境:nginx+tomcat 部署方 ...

  8. SVO实时全局光照:中等规模场景的GI实现

    RTGI人生成就点unlocked! 快速集成DR+AO+SVO GI,针对中等场景粒度,初步具备全功能,暂未重度优化.附测试对比图.

  9. go2shell的安装与修改默认terminal方法

    go2shell的安装与修改默认terminal方法   1. 安装go2shell后,打开finder的application文件夹,找到go2shell 2. 按住command,用鼠标将go2s ...

  10. eclipse无线连接android真机能进调试

    将手机与电脑连接到同一个网段, 在手机上安装wifi adb程序,并打开,会得到一个IP及端口,比如是 192.168.1.126:5555 进入android sdk目录sdk\platform-t ...