<?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. Leetcode 27 Remove Element STL

    和remove zero类似的方法完成该题 class Solution { public: int removeElement(vector<int>& nums, int va ...

  2. spring源码 — 三、AOP代理生成

    AOP代理生成 AOP就是面向切面编程,主要作用就是抽取公共代码,无侵入的增强现有类的功能.从一个简单的spring AOP配置开始: <?xml version="1.0" ...

  3. 充分利用 UE4 中的噪声

    转自:https://www.unrealengine.com/zh-CN/blog/getting-the-most-out-of-noise-in-ue4 UE4 推出基于材质的程序式噪声已经有一 ...

  4. 在 Xen 虚拟机下修改系统当前时间

    在 Xen 虚拟机下修改系统当前时间 Xen 虚拟机默认不允许不同的虚拟机使用不同的系统时间,因此所有虚拟机的系统时间都会同宿主机的系统时间严格同步,用 date 命令修改虚拟机系统时间时虽然提示成功 ...

  5. HTML 邮件链接,超链接发邮件

    在网页中可以设置如“联系我们”.“问题反馈”等所谓的邮箱链接,类似网页超链接,只是可以直接打开默认邮箱程序. 使用<a href="mailto:youEMail@xxx.yyy&qu ...

  6. tbb flow graph node types

  7. linux centos java 应用服务器配置

    备忘: https://oneinstack.com/ 1.用root装jdk nginx.tomcat. 2.配置tomcat主机,上传应用.修改数据库连接帐号,修改log4j文件路径.3.安装my ...

  8. 美行Thinkpad八通道快捷入口

    美行Thinkpad八通道快捷入口 链接: http://shop.lenovo.com/perksoffer/us/en/laptops/thinkpad/?__followRobots=true打 ...

  9. 关于 c# 操作 world

    把数据存放在datatable 中并循环取出来数据然后再保存在world中 protected void ExportToWord(DataSet Ads) { try { Object Nothin ...

  10. c# 小数取整

    向上取整 math.ceiling() = math.ceiling( math.ceiling( 向下取整 math.) = math. math. C#取整函数实例应用详解 C#取整函数的相关使用 ...